Forked from cartant/medium-rxjs-publish-multicast.ts
Last active
July 20, 2019 22:19
-
-
Save LayZeeDK/102160de9a8e098d08b7cb329aca35e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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