Rxjs Scheduler: What is the difference between asap and async?

Can someone tell me the difference between Scheduler.asap and Scheduler.async?

It looks like me:

const observable = Observable.create(function (observer) {
  observer.next(1);
  observer.next(2);
  observer.next(3);
  observer.complete();
})
.observeOn(asap);
//.observeOn(async);

console.log('just before subscribe');
observable.subscribe({
  next: x => console.log('got value ' + x),
  complete: () => console.log('done'),
});
console.log('just after subscribe');

Return:

just before subscribe
just after subscribe
got value 1
got value 2
got value 3
done

Code - https://stackblitz.com/edit/rxjs-85vczc?file=app/hello.component.ts

+4
source share
1 answer

The scheduler is asyncbest used for temporary operations (uses setIntervaleven if the time delay is 0 ... ex. Polling), where the scheduler is asapbest suited for asynchronous operations, which should happen as quickly as possible, regardless of time.

More details here .

0
source

Source: https://habr.com/ru/post/1689527/


All Articles