Calling next with Schedulers
You’ve learned a heaping pile of different ways to create observables throughout this book. The secret you didn’t know was how Rx decides exactly when to send a new value down the chain. The tool Rx uses for this is called a scheduler, and Rx ships many options for you to choose from. By default, every observable does not use a scheduler to plan out events, instead they emit all values synchronously. Run the following code to see this in action:
| of('Hello') |
| .subscribe(next => console.log(next)); |
| |
| console.log('World'); |
This snippet does not pass a scheduler into the of constructor, so it just runs synchronously. This example logs Hello before World. Now, we can add the asap scheduler to the mix, which delays ...
Get Build Reactive Websites with RxJS now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.