A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/Reactive-Extensions/RxJS/wiki/Recipes below:

Recipes · Reactive-Extensions/RxJS Wiki · GitHub

There are many ways of handling errors in RxJS. This will cover a number of recipes when handling errors:

Incremental retry with retryWhen

This example will show how you can back off a retry for a number of seconds between tries instead of retrying them all at once.

function identity(x) { return x; }

Rx.Observable.create(o => {
      console.log('subscribing');
      o.onError(new Error('always fails'));
  }).retryWhen(function (attempts) {
      return Rx.Observable.range(1, 3)
        .zip(attempts, identity)
        .flatMap(function (i) {
          console.log('delay retry by ' + i + ' second(s)');
          return Rx.Observable.timer(i * 1000);
      });
  }).subscribe();
  
/*
subscribing
delay retry by 1 second(s)
subscribing
delay retry by 2 second(s)
subscribing
delay retry by 3 second(s)
subscribing
*/

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4