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


TypeScript rxjs.timer函數代碼示例

本文整理匯總了TypeScript中rxjs.timer函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript timer函數的具體用法?TypeScript timer怎麽用?TypeScript timer使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了timer函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: it

  it('should raises error when promise rejects', (done: MochaDone) => {
    const e1 = concat(
      of(1),
      timer(10).pipe(mapTo(2)),
      timer(10).pipe(mapTo(3)),
      timer(100).pipe(mapTo(4))
    );
    const expected = [1, 2];
    const error = new Error('error');

    e1.pipe(
      debounce((x: number) => {
        if (x === 3) {
          return new Promise((resolve: any, reject: any) => { reject(error); });
        } else {
          return new Promise((resolve: any) => { resolve(42); });
        }
      })
    ).subscribe((x: number) => {
      expect(x).to.equal(expected.shift()); },
      (err: any) => {
        expect(err).to.be.an('error', 'error');
        expect(expected.length).to.equal(0);
        done();
      }, () => {
        done(new Error('should not be called'));
      });
  });
開發者ID:DallanQ,項目名稱:rxjs,代碼行數:28,代碼來源:debounce-spec.ts

示例2: combineLatest1

  combineLatest1() {
    // timerOne emits first value at 1s, then once every 4s
    const timerOne = timer(1000, 4000);
    // timerTwo emits first value at 2s, then once every 4s
    const timerTwo = timer(2000, 4000);
    // timerThree emits first value at 3s, then once every 4s
    const timerThree = timer(3000, 4000);

    // when one timer emits, emit the latest values from each timer as an array
    const combined = combineLatest(timerOne, timerTwo, timerThree);

    const subscribe = combined.subscribe(
      ([timerValOne, timerValTwo, timerValThree]) => {
        /*
      	Example:
        timerOne first tick: 'Timer One Latest: 1, Timer Two Latest:0, Timer Three Latest: 0
        timerTwo first tick: 'Timer One Latest: 1, Timer Two Latest:1, Timer Three Latest: 0
        timerThree first tick: 'Timer One Latest: 1, Timer Two Latest:1, Timer Three Latest: 1
      */
        console.log(
          `Timer One Latest: ${timerValOne},
         Timer Two Latest: ${timerValTwo},
         Timer Three Latest: ${timerValThree}`
        );
      }
    );
  }
開發者ID:zwvista,項目名稱:SampleMisc,代碼行數:27,代碼來源:combining.service.ts

示例3: constructor

 constructor() {
   this.everySecond$ = timer(1000, 1000).pipe(
     share(),
   );
   this.everyHalfSecond$ = timer(500, 500).pipe(
     share(),
   );
 }
開發者ID:m-sc,項目名稱:yamcs,代碼行數:8,代碼來源:Synchronizer.ts

示例4: it

  it('should throttle events multiple times', () => {
    const expected = ['1-0', '2-0'];
    concat(
      timer(0, 10, rxTestScheduler).pipe(take(3), map((x: number) => '1-' + x)),
      timer(80, 10, rxTestScheduler).pipe(take(5), map((x: number) => '2-' + x))
    ).pipe(
      throttleTime(50, rxTestScheduler)
    ).subscribe((x: string) => {
        expect(x).to.equal(expected.shift());
      });

    rxTestScheduler.flush();
  });
開發者ID:DallanQ,項目名稱:rxjs,代碼行數:13,代碼來源:throttleTime-spec.ts

示例5: it

  it('should emit a single value immediately', () => {
    const dueTime = time('|');
    const expected =     '(x|)';

    const source = timer(dueTime, rxTestScheduler);
    expectObservable(source).toBe(expected, {x: 0});
  });
開發者ID:deanius,項目名稱:RxJS,代碼行數:7,代碼來源:timer-spec.ts

示例6: windowWhen1

  windowWhen1() {
    // emit immediately then every 1s
    const source = timer(0, 1000);
    const example = source.pipe(
      // close window every 5s and emit observable of collected values from source
      windowWhen(() => interval(5000)),
      tap(_ => console.log('NEW WINDOW!'))
    );

    const subscribeTwo = example
      .pipe(
        // window emits nested observable
        mergeAll()
        /*
          output:
          "NEW WINDOW!"
          0
          1
          2
          3
          4
          "NEW WINDOW!"
          5
          6
          7
          8
          9
        */
      )
      .subscribe(val => console.log(val));
  }
開發者ID:zwvista,項目名稱:SampleMisc,代碼行數:31,代碼來源:transforming.service.ts

示例7: of

        const source = of(expiresAt).pipe(flatMap(expiration => {
            const now = Date.now();

            // Use the delay in a timer to
            // run the refresh at the proper time
            return timer(Math.max(1, expiresAt - now));
        }));
開發者ID:pastorsj,項目名稱:bannablog,代碼行數:7,代碼來源:authentication.service.ts

示例8: timer

 registry.register('job-obs-async', createJobHandler<number, number, number>(arg => {
   return timer(1).pipe(
     take(3),
     take(1),
     map(() => arg + 1),
   );
 }));
開發者ID:angular,項目名稱:angular-cli,代碼行數:7,代碼來源:simple-scheduler_spec.ts

示例9: observableTimer

    .pipe(catchError((error : Error, source) => {
      if (!shouldRetry(error)) {
        throw error;
      }
      const currentError = error instanceof RequestError &&
        isOfflineRequestError(error) ?  ERROR_TYPES.OFFLINE : ERROR_TYPES.REGULAR;

      const maxRetry = currentError === ERROR_TYPES.OFFLINE ?
        maxRetryOffline : maxRetryRegular;

      if (currentError !== lastError) {
        retryCount = 0;
        lastError = currentError;
      }

      if (++retryCount > maxRetry) {
        throw error;
      }

      if (onRetry) {
        onRetry(error, retryCount);
      }

      const delay = Math.min(
        baseDelay * Math.pow(2, retryCount - 1),
        maxDelay
      );

      const fuzzedDelay = getFuzzedDelay(delay);
      return observableTimer(fuzzedDelay).pipe(
        mergeMap(() => source));
    }));
開發者ID:canalplus,項目名稱:rx-player,代碼行數:32,代碼來源:backoff.ts


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