當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。