Skip to content

Instantly share code, notes, and snippets.

@huang47
Created December 20, 2014 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huang47/b99c3d6a26aa22290705 to your computer and use it in GitHub Desktop.
Save huang47/b99c3d6a26aa22290705 to your computer and use it in GitHub Desktop.
var Rx = require('rx');
var e1 = new Rx.Subject();
var e2 = new Rx.Subject();
var e3 = new Rx.Subject();
var e1s = e1.asObservable();
var e2s = e2.asObservable();
var e3s = e3.asObservable();
e3s.
startWith(true).
flatMapLatest(function () {
return e1s.
flatMapLatest(function () {
return e2s.delay(1000);
}).
takeUntil(e3s);
}).
forEach(function (value) {
console.log('value %s', value);
});
// NOT emit e2
e1.onNext('e1');
e2.onNext('e2');
setTimeout(function () {
// abort e2
e3.onNext('e3');
}, 500);
setTimeout(function () {
e1.onNext('e1');
// should emit e2 since e3 is not happened
e2.onNext('e2');
}, 2000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment