Skip to content

Instantly share code, notes, and snippets.

@huang47
Created December 23, 2014 01:16
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/233c2fba3b22b6ea5b0f to your computer and use it in GitHub Desktop.
Save huang47/233c2fba3b22b6ea5b0f to your computer and use it in GitHub Desktop.
var Rx = require('rx');
var subjects = {};
function create(sn) {
var s = new Rx.Subject();
subjects[sn] = s;
return Rx.Observable.create(function (o) {
var so = s.asObservable();
so.forEach(o.onNext.bind(o), o.onError.bind(o), o.onCompleted.bind(o));
return function () {
console.log('dispose %s', sn);
}
});
}
var o = create(1);
var c = console.log.bind(console);
var t = o.forEach(c, c, function () {
console.log('complete');
});
Rx.Observable.merge(
create(2),
create(3),
create(4)
).
takeUntil(create(5)).
forEach(c, c, function () {
console.log('completed');
});
subjects[5].onNext();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment