Created
August 23, 2017 03:37
-
-
Save cartant/59b5db376ff16cf32a6c6da21aea3ba3 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 { Observable } from "rxjs/Observable"; | |
import { Subject } from "rxjs/Subject"; | |
import "rxjs/add/observable/defer"; | |
import "rxjs/add/observable/of"; | |
import "rxjs/add/operator/multicast"; | |
const source = Observable.defer(() => Observable.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.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