Could somebody tell me the difference between Scheduler.asap and Scheduler.async?
Looks the same for 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');
Returns:
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
From: Randall Koutnik Book “Build Reactive Websites with RxJS.” :
RxJS has two different types of asynchronous schedulers: asap and async. The key difference is that asap schedules the observable event to be run using the micro task queue (process.nextTick() in Node.js, or setTimeout in the browser). This means that the event runs after any synchronous code but before any other scheduled asynchronous tasks. The other major scheduler, async, schedules using setTimeout, and is appropriate for some time-based operations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With