Created
June 18, 2019 06:28
-
-
Save lydemann/f8cdd009dfaa03072300fd7883671334 to your computer and use it in GitHub Desktop.
Demo of the different RxJs schedulers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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