本文整理汇总了TypeScript中rxjs.defer函数的典型用法代码示例。如果您正苦于以下问题:TypeScript defer函数的具体用法?TypeScript defer怎么用?TypeScript defer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了defer函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should render the error message if the poll response`s job status is "failed"', fakeAsync(() => {
const searchResponse = new PcapStatusResponse();
searchResponse.jobId = '42';
pcapService.submitRequest = jasmine.createSpy('submitRequest').and.returnValue(
defer(() => Promise.resolve(searchResponse))
);
const pollResponse = new PcapStatusResponse();
pollResponse.jobStatus = 'FAILED';
pcapService.pollStatus = jasmine.createSpy('pollStatus').and.returnValue(
defer(() => Promise.resolve(pollResponse))
);
component.onSearch(new PcapRequest());
tick();
fixture.detectChanges();
expect(
fixture.debugElement.query(By.css('[data-qe-id="error"]'))
.nativeElement
.textContent.trim()
).toBe(`Query status: ${pollResponse.jobStatus}. Check your filter criteria and try again!`);
}));
示例2: intercept
public async intercept(
interceptors: NestInterceptor[],
args: any[],
instance: Controller,
callback: (...args) => any,
next: () => Promise<any>,
): Promise<any> {
if (!interceptors || isEmpty(interceptors)) {
return await await next();
}
const context = this.createContext(args, instance, callback);
const start$ = defer(() => this.transformDeffered(next));
/***
const nextFn = (i: number) => async () => {
if (i <= interceptors.length) {
return start$;
}
return await interceptors[i].intercept(context, nextFn(i + 1) as any);
};
*/
const result$ = await interceptors.reduce(
async (stream$, interceptor) =>
await interceptor.intercept(context, await stream$),
Promise.resolve(start$),
);
return await result$.toPromise();
}
示例3: mergeMap
mergeMap(() => defer(() =>
of(2, asapScheduler)
).pipe(
mergeMap(() => defer(() =>
of(3, asapScheduler)
))
))
示例4: Actions
useFactory: (): Observable<any> => {
if (typeof factoryOrSource === 'function') {
return new Actions(defer(factoryOrSource));
}
return new Actions(factoryOrSource);
},
示例5: observableDefer
/**
* Set the MediaKeys object on the HTMLMediaElement if it is not already on the
* element.
* If a MediaKeys was already set on it, dispose of it before setting the new
* one.
*
* /!\ Mutates heavily currentMediaKeysInfos
* @param {Object} mediaKeysInfos
* @param {HTMLMediaElement} mediaElement
* @param {Object} currentMediaKeysInfos
* @returns {Observable}
*/
export default function attachMediaKeys(
mediaKeysInfos: IMediaKeysInfos,
mediaElement : HTMLMediaElement,
currentMediaKeysInfos: MediaKeysInfosStore
) : Observable<unknown> {
return observableDefer(() => {
const previousState = currentMediaKeysInfos.getState(mediaElement);
const {
keySystemOptions,
mediaKeySystemAccess,
mediaKeys,
sessionsStore,
} = mediaKeysInfos;
currentMediaKeysInfos.setState(mediaElement, {
keySystemOptions,
mediaKeySystemAccess,
mediaKeys,
sessionsStore,
});
return (
previousState && previousState.sessionsStore !== sessionsStore ?
previousState.sessionsStore.closeAllSessions() :
observableOf(null)
).pipe(mergeMap(() => {
if (mediaElement.mediaKeys === mediaKeys) {
return observableOf(null);
}
log.debug("EME: Setting MediaKeys");
return setMediaKeys(mediaElement, mediaKeys);
}));
});
}
示例6: observableDefer
/**
* Trigger the `endOfStream` method of a MediaSource.
*
* If the MediaSource is ended/closed, do not call this method.
* If SourceBuffers are updating, wait for them to be updated before closing
* it.
* @param {MediaSource} mediaSource
* @returns {Observable}
*/
export default function triggerEndOfStream(
mediaSource : MediaSource
) : Observable<null> {
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);
}));
});
}