本文整理匯總了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);
}));
});
}