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>
 
//example promise that will resolve or reject based on input
const myPromise = (willReject) => {
    return new Promise((resolve, reject) => {
    if(willReject){
        reject('Rejected!');
    }
    resolve('Resolved!');
  })
}
//emit true, then false
const source = Rx.Observable.of(true, false);
const example = source
    .mergeMap(val => Rx.Observable
    //turn promise into observable
    .fromPromise(myPromise(val))
    //catch and gracefully handle rejections
    .catch(error => Rx.Observable.of(`Error: ${error}`)))
//output: 'Error: Rejected!', 'Resolved!'
const subscribe = example.subscribe(val => console.log(val));
Output 300px

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

Dismiss x
public
Bin info
anonymouspro
0viewers