本文整理匯總了TypeScript中rxjs/operators.multicast函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript multicast函數的具體用法?TypeScript multicast怎麽用?TypeScript multicast使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了multicast函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('should multicast a ConnectableObservable', (done) => {
const expected = [1, 2, 3, 4];
const source = new Subject<number>();
const connectable = source.pipe(multicast(new Subject<number>())) as ConnectableObservable<number>;
const replayed = connectable.pipe(multicast(new ReplaySubject<number>())) as ConnectableObservable<number>;
connectable.connect();
replayed.connect();
source.next(1);
source.next(2);
source.next(3);
source.next(4);
source.complete();
replayed.pipe(
tap({
next(x) {
expect(x).to.equal(expected.shift());
},
complete() {
expect(expected.length).to.equal(0);
}
})
).subscribe(null, done, done);
});
示例2: type
type('should infer the type for the pipeable operator', () => {
/* tslint:disable:no-unused-variable */
const source = of<number>(1, 2, 3);
// TODO: https://github.com/ReactiveX/rxjs/issues/2972
const result: ConnectableObservable<number> = multicast(() => new Subject<number>())(source);
/* tslint:enable:no-unused-variable */
});
示例3: multicast1
multicast1() {
// emit every 2 seconds, take 5
const source = interval(2000).pipe(take(5));
const example = source.pipe(
// since we are multicasting below, side effects will be executed once
tap(() => console.log('Side Effect #1')),
mapTo('Result!')
);
// subscribe subject to source upon connect()
const multi = example.pipe(multicast(() => new Subject())) as ConnectableObservable<string>;
/*
subscribers will share source
output:
"Side Effect #1"
"Result!"
"Result!"
...
*/
const subscriberOne = multi.subscribe(val => console.log(val));
const subscriberTwo = multi.subscribe(val => console.log(val));
// subscribe subject to source
multi.connect();
}