本文整理汇总了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();
}