Skip to content

Instantly share code, notes, and snippets.

@huang47
Created November 23, 2014 03:44
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/bd25a913d8f56db369ce to your computer and use it in GitHub Desktop.
Save huang47/bd25a913d8f56db369ce to your computer and use it in GitHub Desktop.
var Rx = require('rx');
var s = new Rx.Subject();
var r = s.asObservable().replay();
r.connect();
s.onNext(1);
s.onNext(2);
s.onNext(3);
r.forEach(function (x) {
console.log('r1 %s', x);
});
// r1 1
// r1 2
// r1 3
s.onNext(4);
s.onNext(5);
s.onNext(6);
// r1 4
// r1 5
// r1 6
r.forEach(function (x) {
console.log('r2 %s', x);
});
// r2 1
// r2 2
// r2 3
// r2 4
// r2 5
// r2 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment