當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript rxjs.defer函數代碼示例

本文整理匯總了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!`);
  }));
開發者ID:merrimanr,項目名稱:incubator-metron,代碼行數:25,代碼來源:pcap-panel.component.spec.ts

示例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();
 }
開發者ID:timokae,項目名稱:nest,代碼行數:27,代碼來源:interceptors-consumer.ts

示例3: mergeMap

 mergeMap(() => defer(() =>
   of(2, asapScheduler)
 ).pipe(
   mergeMap(() => defer(() =>
     of(3, asapScheduler)
   ))
 ))
開發者ID:jaychsu,項目名稱:RxJS,代碼行數:7,代碼來源:mergeMap-spec.ts

示例4: Actions

    useFactory: (): Observable<any> => {
      if (typeof factoryOrSource === 'function') {
        return new Actions(defer(factoryOrSource));
      }

      return new Actions(factoryOrSource);
    },
開發者ID:AlexChar,項目名稱:platform,代碼行數:7,代碼來源:testing.ts

示例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);
    }));
  });
}
開發者ID:canalplus,項目名稱:rx-player,代碼行數:47,代碼來源:attach_media_keys.ts

示例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);
    }));
  });
}
開發者ID:canalplus,項目名稱:rx-player,代碼行數:40,代碼來源:end_of_stream.ts


注:本文中的rxjs.defer函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。