RxJS Sample: retryWhen()

RxJS sample of retryWhen operator. The sample code retries 3 times with a delay if the observable throw an error. And then just gives up with the last error.

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/4.0.7/rx.all.js"></script>
<div id="output" />

Babel + JSX

const output = document.getElementById("output");

function print(s) {
  output.innerHTML += (s + "<br/>");
}

const o = Rx.Observable.fromPromise(fetch("https://www.google.ru/search=432"));

o.retryWhen(errors => errors
               .do(val => console.log(val))
               .delay(2000)
            )
).subscribe(
  (x) => print("onNext: " + x),
  (err) => print("onError: " + err),
  () => print("onCompleted")
);