Skip to content

Instantly share code, notes, and snippets.

@lydemann
Created June 18, 2019 06:28
Show Gist options
  • Save lydemann/f8cdd009dfaa03072300fd7883671334 to your computer and use it in GitHub Desktop.
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))
.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