Created
December 20, 2014 20:11
-
-
Save huang47/626569cfd3e0a06c8eeb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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