Skip to content

Instantly share code, notes, and snippets.

@mattpodwysocki
Last active September 21, 2015 20:48
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 mattpodwysocki/79b82b9d18030be2c494 to your computer and use it in GitHub Desktop.
Save mattpodwysocki/79b82b9d18030be2c494 to your computer and use it in GitHub Desktop.
Why scheduling matters with RxJS
Rx.Observable.fromArray([1,2,3], Rx.Scheduler.currentThread)
.flatMap(function (x) {
return Rx.Observable.repeat(x, x);
})
.subscribe(function (x) {
console.log('Next: %s', x)
});
// => Next 1
// => Next 2
// => Next 2
// => Next 3
// => Next 3
// => Next 3
Rx.Observable.fromArray([1,2,3], Rx.Scheduler.immediate)
.flatMap(function (x) {
return Rx.Observable.repeat(x, x);
})
.subscribe(function (x) {
console.log('Next: %s', x)
});
// => Next 1
// => Next 2
// => Next 3
// => Next 2
// => Next 3
// => Next 3
Rx.Observable.fromArray([1,2,3], Rx.Scheduler.default)
.flatMap(function (x) {
return Rx.Observable.repeat(x, x);
})
.subscribe(function (x) {
console.log('Next: %s', x)
});
// => Next 1
// => Next 2
// => Next 2
// => Next 3
// => Next 3
// => Next 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment