本文整理匯總了TypeScript中rxjs.race函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript race函數的具體用法?TypeScript race怎麽用?TypeScript race使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了race函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: waitUntilWatchIsReady
export function waitUntilWatchIsReady(
stream: NodeJS.EventEmitter,
opts: IWatchOptions = {}
) {
const buildOutput$ = new Rx.Subject<string>();
const onDataListener = (data: Buffer) =>
buildOutput$.next(data.toString('utf-8'));
const onEndListener = () => buildOutput$.complete();
const onErrorListener = (e: Error) => buildOutput$.error(e);
stream.once('end', onEndListener);
stream.once('error', onErrorListener);
stream.on('data', onDataListener);
return Rx.race(getWatchHandlers(buildOutput$, opts))
.pipe(
mergeMap(whenReady => whenReady),
finalize(() => {
stream.removeListener('data', onDataListener);
stream.removeListener('end', onEndListener);
stream.removeListener('error', onErrorListener);
buildOutput$.complete();
})
)
.toPromise();
}
示例2: it
it('should race a single observable', () => {
const e1 = cold('---a-----b-----c----|');
const e1subs = '^ !';
const expected = '---a-----b-----c----|';
const result = race(e1);
expectObservable(result).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
示例3: race2
race2() {
// Throws an error and ignores the other observables.
const first = of('first').pipe(
delay(100),
map(_ => {
throw 'error';
})
);
const second = of('second').pipe(delay(200));
const third = of('third').pipe(delay(300));
// nothing logged
race(first, second, third).subscribe(val => console.log(val));
}
示例4: observableDefer
return observableDefer(() => {
log.debug("Init: Trying to call endOfStream");
if (mediaSource.readyState !== "open") {
log.debug("Init: MediaSource not open, cancel endOfStream");
return observableOf(null);
}
const { sourceBuffers } = mediaSource;
const updatingSourceBuffers = getUpdatingSourceBuffers(sourceBuffers);
if (!updatingSourceBuffers.length) {
log.info("Init: Triggering end of stream");
mediaSource.endOfStream();
return observableOf(null);
}
log.debug("Init: Waiting SourceBuffers to be updated before calling endOfStream.");
const updatedSourceBuffers$ = updatingSourceBuffers
.map((sourceBuffer) => onUpdate$(sourceBuffer).pipe(take(1)));
return observableRace(
observableMerge(...updatedSourceBuffers$).pipe(takeLast(1)),
onRemoveSourceBuffers$(sourceBuffers).pipe(take(1))
).pipe(mergeMap(() => {
return triggerEndOfStream(mediaSource);
}));
});