zl程序教程

您现在的位置是:首页 >  其它

当前栏目

[RxJS] Asynchronous Execution Scheduler

Rxjs scheduler execution Asynchronous
2023-09-14 09:00:45 时间

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)