Skip to content

Instantly share code, notes, and snippets.

@ArtemRomanovsky
Created February 19, 2020 15:26
Show Gist options
  • Save ArtemRomanovsky/76d716fce150e9cad8b033d6fb2ca329 to your computer and use it in GitHub Desktop.
Save ArtemRomanovsky/76d716fce150e9cad8b033d6fb2ca329 to your computer and use it in GitHub Desktop.
const observable = Rx.Observable
.interval (1000)
.take (3)
.share ()
const observable = Rx.Observable
.interval(1000)
.take(3)
.share()
// Uses factory method inside, sonething like
// factory() {
// return new Rx.Subject();
// }
const observerA = {
next: (x) => console.log('A next ' + x) ,
complete: () => console.log('A done')
};
const observerB = {
next: (x) => console.log('B next ' + x) ,
complete: () => console.log('B done')
};
observable.subscribe(observerA);
setTimeout(() => {
observable.subscribe(observerB);
}, 4000)
// Result will be
// A next 0
// A next 1
// A next 2
// A done
// B next 0
// B next 1
// B next 2
// B done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment