Considering I have the following code:
let Rx = window['rxjs'];
const { of,
queueScheduler,
asapScheduler,
asyncScheduler,
animationFrameScheduler
} = Rx;
const { observeOn, tap } = Rx.operators;
console.clear();
let source$ = of(1, 2, 3, asapScheduler).pipe(
tap((v) => {
console.log('tap ', v);
}),
)
source$.subscribe((v) => {
console.log('Value ', v);
Promise.resolve().then(() => {
console.log('Microtask value ', v);
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/6.2.1/rxjs.umd.js"></script>
Which I use asapScheduler operator.
As per the documentation,
asap will wait for the current synchronously executing code to end and then it will try to execute the given task as fast as possible.
What's the execution order of the above code? How do they work? I would not have expected that the tap3 to print at the last
Below are the output,
tap 1
Value 1
tap 2 // here why did this not print Microtask value 1 and Microtask value 2 after printing tap1 and value1?
Value 2
Microtask value 1
Microtask value 2
tap 3
Value 3
Microtask value 3