Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Demo of the different RxJs schedulers
import { of, merge, asapScheduler, asyncScheduler, animationFrameScheduler, queueScheduler } from 'rxjs';
import { filter, startWith, observeOn } from 'rxjs/operators';
const delay = 0;
const async$ = of('async')
.pipe(observeOn(asyncScheduler, delay)); // macro queue
const asap$ = of('asap')
.pipe(observeOn(asapScheduler, delay)); // micro queue
const animationFrame$ = of('animationFrameScheduler')
.pipe(observeOn(animationFrameScheduler, delay)); // before browser repaints
const queue$ = of('queue')
.pipe(observeOn(queueScheduler, delay)); // sync
merge(async$, asap$, animationFrame$, queue$)
.pipe(filter(x => !!x))
.subscribe(console.log);
console.log('after subscription')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.