Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save LayZeeDK/102160de9a8e098d08b7cb329aca35e8 to your computer and use it in GitHub Desktop.
Save LayZeeDK/102160de9a8e098d08b7cb329aca35e8 to your computer and use it in GitHub Desktop.
import { defer, Observable, of, Subject } from "rxjs";
import { multicast } from "rxjs/operators";
const source = defer(() => of(
Math.floor(Math.random() * 100)
));
function observer(name: string) {
return {
next: (value: number) => console.log(`observer ${name}: ${value}`),
complete: () => console.log(`observer ${name}: complete`)
};
}
const m = source.pipe(
multicast(new Subject<number>())
);
m.subscribe(observer("a"));
m.subscribe(observer("b"));
m.connect();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment