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>JS Bin</title>
  <script src="https://unpkg.com/rxjs@5.1.1/bundles/Rx.min.js"></script>
</head>
<body>
</body>
</html>
 
let arr = [1,2,3,4,'random',6,7,8,9,10];
Rx.Observable.from(arr)
  .concatMap(val => {
    let attempts = 0;
    return Rx.Observable.of(val)
      .delay(500)
      .concatMap(val => randomFunc(val)
        .catch((err, caught) => {
          console.log('log error');
          if (attempts++ === 1) {
            return Rx.Observable.of(err);
          } else {
            return caught;
          }
        })
      );
  })
  .subscribe(val => console.log(val));
function randomFunc(dt) {
  return Rx.Observable.create(observer => {
    if (dt === 'random') {
      observer.error(`error received ${dt}`);
    } else {
      observer.next(dt);
      observer.complete();
    }
  });
}
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
martinsikpro
0viewers