DEV Community

netsi1964 ๐Ÿ™๐Ÿป
netsi1964 ๐Ÿ™๐Ÿป

Posted on

1

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.

Top comments (0)

Sentry image

See why 4M developers consider Sentry, โ€œnot bad.โ€

Fixing code doesnโ€™t have to be the worst part of your day. Learn how Sentry can help.

Learn more