[RxJS] Asynchronous Execution Scheduler

microtask -> requestAnimationFrame -> macrotask

 

Each scheduler can just take callback as arguement

asyncScheduler.schedule(() => console.log('async')) // similar to setTimeout()

asapScheduler.schedule(() => console.log('microtask')) 

animationFrameScheduler.scheduler(() => console.log('frame'))

queueScheduler.schedule(() => { // schedule additional task })

 

or 

asyncScheduler.schedule(console.log, 200, 'async') // call console.log with 'async' after 200 ms

asapScheduler.schedule(console.log, null, 'microtask') // asapScheduler has no delay

animationFrameScheduler.schedule(console.log, null, 'aframe')

queueScheduler.schedule(() => {})

 

Scheduler as arguement

of(1,2,3 asyncScheduler).subscribe(observer);

 

observeOn operator

interval(20).pipe(
  observeOn(animationFrameScheduler)
).subscribe(observer);

 

subscribeOn operator

of(1,2,3).pipe(
 subscribeOn(asyncSchedulder)
).subscribe(observer)

 

posted @ 2022-09-27 21:41  Zhentiw  阅读(18)  评论(0编辑  收藏  举报