当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript operators.retry函数代码示例

本文整理汇总了TypeScript中rxjs/operators.retry函数的典型用法代码示例。如果您正苦于以下问题:TypeScript retry函数的具体用法?TypeScript retry怎么用?TypeScript retry使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了retry函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: retry1

 retry1() {
   // emit value every 1s
   const source = interval(1000);
   const example = source.pipe(
     mergeMap(val => {
       // throw error for demonstration
       if (val > 5) {
         return throwError('Error!');
       }
       return of(val);
     }),
     // retry 2 times on error
     retry(2)
   );
   /*
     output:
     0..1..2..3..4..5..
     0..1..2..3..4..5..
     0..1..2..3..4..5..
     "Error!: Retried 2 times then quit!"
   */
   const subscribe = example.subscribe({
     next: val => console.log(val),
     error: val => console.log(`${val}: Retried 2 times then quit!`)
   });
 }
开发者ID:zwvista,项目名称:SampleMisc,代码行数:26,代码来源:error-handling.service.ts

示例2: switchMap

 switchMap(() =>
   fetchServicePlans(parent.id).pipe(
     retry(2),
     map(({ response }) => response),
     map((plans: string[]) => {
       return plans.map(name => ({ name }));
     })
   )
开发者ID:dcos,项目名称:dcos-ui,代码行数:8,代码来源:index.ts

示例3: it

  it('should retry just fine', () => {
    const e1 =  cold('---a--b--c--d--e--#');
    const e1subs =  ['^                 !                  ',
                   '                  ^                 !'];
    const expected = '---a--b--c--d--e-----a--b--c--d--e--#';

    expectObservable(e1.pipe(share(), retry(1))).toBe(expected);
    expectSubscriptions(e1.subscriptions).toBe(e1subs);
  });
开发者ID:DallanQ,项目名称:rxjs,代码行数:9,代码来源:share-spec.ts

示例4: it

  it('should return a never observable given an async just-throw source and no count', () => {
    const source = cold('-#'); // important that it's not a sync error
    const unsub =       '                                     !';
    const expected =    '--------------------------------------';

    const result = source.pipe(retry());

    expectObservable(result, unsub).toBe(expected);
  });
开发者ID:DallanQ,项目名称:rxjs,代码行数:9,代码来源:retry-spec.ts

示例5: it

  it('overrides protractor specs', (done) => {
    host.scopedSync().rename(normalize('./e2e/app.e2e-spec.ts'),
      normalize('./e2e/renamed-app.e2e.spec.ts'));

    const overrides = { specs: ['./e2e/renamed-app.e2e.spec.ts'] };

    runTargetSpec(host, protractorTargetSpec, overrides).pipe(
      retry(3),
    ).toPromise().then(done, done.fail);
  }, 60000);
开发者ID:DevIntent,项目名称:angular-cli,代码行数:10,代码来源:works_spec_large.ts

示例6: linuxOnlyIt

  linuxOnlyIt('overrides protractor specs', (done) => {
    host.scopedSync().rename(normalize('./e2e/app.e2e-spec.ts'),
      normalize('./e2e/renamed-app.e2e-spec.ts'));

    const overrides = { specs: ['./e2e/renamed-app.e2e-spec.ts'] };

    runTargetSpec(host, protractorTargetSpec, overrides).pipe(
      retry(3),
    ).subscribe(undefined, done.fail, done);
  }, 60000);
开发者ID:iwe7,项目名称:devkit,代码行数:10,代码来源:works_spec_large.ts

示例7: of

 observable1 = constructorZone1.run(() => {
   return of(1, 2, 3).pipe(
       map((n: number) => {
         expect(Zone.current.name).toEqual(constructorZone1.name);
         if (n === 2) {
           throw error;
         }
         return n;
       }),
       retry(1));
 });
开发者ID:angular,项目名称:zone.js,代码行数:11,代码来源:rxjs.Observable.catch.spec.ts

示例8: cold

  'unsubscribed early', () => {
    const source = cold('--1-2-3-#');
    const unsub =       '             !           ';
    const subs =       ['^       !                ',
                      '        ^    !           '];
    const expected =    '--1-2-3---1-2-';

    const result = source.pipe(retry(3));

    expectObservable(result, unsub).toBe(expected);
    expectSubscriptions(source.subscriptions).toBe(subs);
  });
开发者ID:DallanQ,项目名称:rxjs,代码行数:12,代码来源:retry-spec.ts


注:本文中的rxjs/operators.retry函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。