• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript rxjs.timer函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript rxjs.using函数代码示例发布时间:2022-05-25
下一篇:
TypeScript rxjs.throwError函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap