Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>bufferCount</title>
  <script src="https://npmcdn.com/@reactivex/rxjs@5.0.0-beta.3/dist/global/Rx.umd.js"></script>
</head>
<body>
</body>
</html>
 
//emit value every 200ms
const source = Rx.Observable.interval(200);
//output the observable
const main = source
    .map(val => {
        if (val > 5) {
            throw new Error('The request failed somehow.');
        }
        return val;
    })
    .retryWhen(errors => errors
        //log error message
        .do(val => console.log(`Some error that occur ${val}, pauze for 30 seconds.`))
    );
const retry = main
    .map(val => {
        if (val > 5) {
            throw new Error('The request failed somehow.');
        }
        return val;
    })
    .retryWhen(errors => errors
        //log error message
        .do(val => console.log(`Some error that occur ${val}, pauze for 30 seconds.`))
        //restart in 30 seconds
        .delayWhen(val => Rx.Observable.timer(30 * 1000))
    );
const subscribe = retry
    .subscribe({
        next: val => console.log(val),
        error: val => console.log(`This will never happen`)
    });
Output 300px

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers