DEV Community

netsi1964 πŸ™πŸ»
netsi1964 πŸ™πŸ»

Posted on

Use RxJS instead of setTimeout

A small example of using RxJs.

Here we create an observable with of, we then use pipe to take the values (here just "true") into a flow.

Using delay operator to wait for a number of ms. The tap operator lets us "tap into" a stream and "do something".

We log some information, and repeat that pattern 3 times, after which the stream ends.

To start the pattern we use subscribe and after the flow has ended we unsubscribe to the observable stream.

Discussion (0)