Skip to content

Instantly share code, notes, and snippets.

@ArtemRomanovsky
Created February 19, 2020 15:05
Show Gist options
  • Save ArtemRomanovsky/6934f442a9da7ae280d796fd1100bdd4 to your computer and use it in GitHub Desktop.
Save ArtemRomanovsky/6934f442a9da7ae280d796fd1100bdd4 to your computer and use it in GitHub Desktop.
const observable = Rx.Observable.interval(1000).take(5);
const observerA = {...};
const observerB = {...};
const hybrid = {
observers: [],
subscribe: (obs) => {
this.observers.push(obs);
}
next: (v) => {
this.observers.forEach((o) => {
o.next(v);
})
}
}
observable.subscribe(hybrid);
hybrid.subscribe(observerA); // first execution
setTimeout(() => {
hybrid.subscribe(observerB); // the same execution
}, 2000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment