I’m surprised by the order of the output of this Observable example:
<script type="module">
import { of } from 'https://dev.jspm.io/rxjs@6';
console.log("1. before subscribe");
of(["asd"]).subscribe(paramMap => {
console.log("2. in subscribe");
});
console.log("3. after subscribe");
</script>
This produces this output:
1. before subscribe
2. in subscribe
3. after subscribe
How is this output possible? Shouldn’t Observables be asynchronous, and the log in subscribe
happen last?
2
Answers
This is as documented in the RxJs documentation:
And in particular, the documentation for
of
:As mentioned the default for
of
issync
,But you can pass an
asyncScheduler
to make itasync
eg.