There are two async exection context:

  • Microtask Queue - ASAP (Promises, MutationObserver)
  • Macrotask Queue - DO Later (setTimeout, setInterval, requestAnimationFrame)

Microtsk run before Macrotask.

 

RxJS has Schedulers run can modify the exection context:

of("micro").pipe(observeOn(asapScheduler)).subscribe() // Microtask
of("marco").pipe(observeOn(asyncScheduler)).subscribe() // Macrotask

Rarely need to directly using those scheduler.

 

It might be useful for progress bar with animation:

this.process$ = interval(0, animationFrameScheduler).pipe(take(100))

<div [style.width.%]="process$ | async" class="loading"></div>
animationFrameScheduler is built based on RequestAnimationFrame

相关文章:

  • 2021-10-28
  • 2022-01-09
  • 2022-01-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-29
猜你喜欢
  • 2021-10-12
  • 2022-12-23
  • 2021-12-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案