from() operator

This operator can take arrays or a Promise as input and turn them into a stream. To use it, simply call it like this:

// creation-operators/from.js

const promiseStream$ = Rx.Observable.from(
new Promise(resolve => setTimeout(() => resolve("data"),3000))
);

const arrayStream$ = Rx.Observable.from([1, 2, 3, 4]);

promiseStream$.subscribe(data => console.log("data", data));
// emits data after 3 seconds

arrayStream$.subscribe(data => console.log(data));
// emits 1, 2, 3, 4

This saves us a lot of headache by not having to deal with different types of asynchronous calls.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.135.250