Skip to content

Instantly share code, notes, and snippets.

@cartant
Created August 23, 2017 03:37
Show Gist options
  • Save cartant/59b5db376ff16cf32a6c6da21aea3ba3 to your computer and use it in GitHub Desktop.
Save cartant/59b5db376ff16cf32a6c6da21aea3ba3 to your computer and use it in GitHub Desktop.
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