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>RxJS 5 Operators</title>
  <script src="https://unpkg.com/rxjs/bundles/Rx.min.js"></script>
</head>
<body>
</body>
</html>
 
console.clear();
const source$ = Rx.Observable.timer(1, 1000);
source$
  .switchMap(val => {
    if (val > 3) {
      return Rx.Observable.timer(1, 1000).mapTo('This is an error!');
    }
    return Rx.Observable.of(val);
  })
  .catch(err => Rx.Observable.of(`I caught: ${err}`))
  .subscribe(
    val => console.log(val),
    null,
    val => console.log('complete')
  );
Output 300px

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

Dismiss x
public
Bin info
sebaldpro
0viewers