Just because you are utilizing Observables doesn't necessarily imply that everything will be executed in a separate JavaScript callback.
Actually, most default Observables and operators immediately emit everything without using any Scheduler by default. Check out this link for more information on this.
However, when employing operators like delay()
, execution scheduling becomes crucial as demonstrated in this example.
Consider the following scenario:
Observable.from([1,2,3], Scheduler.async)
.subscribe(val => console.log(val));
Observable.from(['a','b','c'], Scheduler.async)
.subscribe(val => console.log(val));
This results in each emission being scheduled into a separate JS callback:
1
"a"
2
"b"
3
"c"
View demo: here
In scenarios where no scheduler is set, all emissions occur immediately (synchronously):
Observable.from([1,2,3])
.subscribe(val => console.log(val));
Observable.from(['a','b','c'])
.subscribe(val => console.log(val));
Resulting in the output:
1
2
3
"a"
"b"
"c"
View demo: here
It's advisable not to rely on third-party libraries for immediate value emissions, as changes may occur leading to unexpected behavior in your code.