Skip to content

Instantly share code, notes, and snippets.

Created June 18, 2019 06:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save lydemann/f8cdd009dfaa03072300fd7883671334 to your computer and use it in GitHub Desktop.
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))
console.log('after subscription')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment