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

TypeScript operators.retryWhen函数代码示例

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

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



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

示例1: load

  load(url: string): Observable<any> {

    return Observable.create(observer => {
      let xhr = new XMLHttpRequest();

      let onLoad = function () {
        if (xhr.status === 200) {
          observer.next(JSON.parse(xhr.responseText));
          observer.complete(); //有 complete(), 似乎正常執行時會呼叫unsubscribe()
        } else {
          observer.error(xhr.statusText);
        }
      };

      xhr.addEventListener('load', onLoad);

      xhr.open('GET', url);
      xhr.send();

      return () => {
        console.log('in unsubscribe');
        xhr.removeEventListener('load', onLoad);
        xhr.abort();
      }

    }).pipe(
      retryWhen(this.retryStrategy({attempts: 4, delayT: 1500}))
    );
  }
开发者ID:Ed-Lee,项目名称:PS-RxJS,代码行数:29,代码来源:data.service.ts


示例2: retryWhen1

 retryWhen1() {
   // emit value every 1s
   const source = interval(1000);
   const example = source.pipe(
     map(val => {
       if (val > 5) {
         // error will be picked up by retryWhen
         throw val;
       }
       return val;
     }),
     retryWhen(errors =>
       errors.pipe(
         // log error message
         tap(val => console.log(`Value ${val} was too high!`)),
         // restart in 5 seconds
         delayWhen(val => timer(val * 1000))
       )
     )
   );
   /*
     output:
     0
     1
     2
     3
     4
     5
     "Value 6 was too high!"
     --Wait 5 seconds then repeat
   */
   const subscribe = example.subscribe(val => console.log(val));
 }
开发者ID:zwvista,项目名称:SampleMisc,代码行数:33,代码来源:error-handling.service.ts


示例3: retry

  retry() {
    // This fake async request will fail the first time
    let fails = 0;
    const fakeAsync = async(new Date().toLocaleTimeString(), () => ++fails <= 1);

    // Add a retry routine using an alert
    const fakeAsyncWithRetries = fakeAsync.pipe(retryWhen(errors => {
      return errors.pipe(switchMap(err => {
        return this.alert.open({
          text: 'Retry?',
          type: AlertType.Warning,
          showCancelButton: true,
        });
      }));
    }));

    this.alert.open({
      text: 'Show current time? (will fail the first time)',
      showCancelButton: true,
      confirmAction: fakeAsyncWithRetries
    }).subscribe(result => {
      this.alert.info(result.value, { title: 'Time' });
    }, err => {
      console.log(err);
      this.alert.error(String(err ? err.reason : err), { title: 'Error' });
    });
  }
开发者ID:ng-vcl,项目名称:ng-vcl,代码行数:27,代码来源:demo.component.ts


示例4: absEndpoint

 delete<T>(endpoint: string, headers?: HttpHeaders) : Observable<T> {
     return this.http.delete<T>(
         absEndpoint(endpoint),
         { headers: authHeaders(headers) }
     ).pipe(
         catchError(unathorizeHandler(this.router)),
         retryWhen(errorRetry())
     );
 }
开发者ID:urandom,项目名称:readeef,代码行数:9,代码来源:api.ts


示例5: rawPost

 rawPost(endpoint: string, body?: any, headers?: HttpHeaders) : Observable<HttpResponse<string>>  {
     return this.http.post(
         absEndpoint(endpoint),
         body,
         { headers: authHeaders(headers), observe: "response", responseType: "text" }
     ).pipe(
         catchError(unathorizeHandler(this.router)),
         retryWhen(errorRetry())
     );
 }
开发者ID:urandom,项目名称:readeef,代码行数:10,代码来源:api.ts


示例6: backoff

function backoff(maxTries, ms) {
 return pipe(
   retryWhen(attempts => zip(range(1, maxTries), attempts)
     .pipe(
       map(([i]) => i * i),
       mergeMap(i =>  timer(i * ms))
     )
   )
 );
}
开发者ID:BobChao87,项目名称:angular,代码行数:10,代码来源:backoff.ts


示例7: backoff

function backoff(maxTries, ms) {
 return pipe(
   retryWhen(attempts => range(1, maxTries)
     .pipe(
       zip(attempts, (i) => i),
       map(i => i * i),
       mergeMap(i =>  timer(i * ms))
     )
   )
 );
}
开发者ID:DallanQ,项目名称:rxjs,代码行数:11,代码来源:backoff.ts


示例8: loadWithFetch

 loadWithFetch(url: string): Observable<any> {
   return Observable.defer(
     () => Observable.fromPromise(fetch(url).then(
       r => {
         if (r.status === 200) {
           return r.json();
         } else {
           return Promise.reject(r.statusText);
         }
       }))
   ).pipe(
     retryWhen(this.retryStrategy())
   );
 }
开发者ID:Ed-Lee,项目名称:PS-RxJS,代码行数:14,代码来源:data.service.ts


示例9: retryWhen

export function retryAfter<T>(
  count: number,
  wait: number
): (source: Observable<T>) => Observable<T> {

  return retryWhen(errors => errors.pipe(
    // Each time an error occurs, increment the accumulator.
    // When the maximum number of retries have been attempted, throw the error.
    scan((acc, error) => {
      if (acc >= count) { throw error; }
      return acc + 1;
    }, 0),
    // Wait the specified number of milliseconds between retries.
    delay(wait)
  ));
}
开发者ID:iproduct,项目名称:course-angular,代码行数:16,代码来源:rx-operators.ts


示例10: higherOrder

export function retryWhen<T>(this: Observable<T>, notifier: (errors: Observable<any>) => Observable<any>): Observable<T> {
  return higherOrder(notifier)(this) as Observable<T>;
}
开发者ID:DallanQ,项目名称:rxjs,代码行数:3,代码来源:retryWhen.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript operators.sample函数代码示例发布时间:2022-05-25
下一篇:
TypeScript operators.retry函数代码示例发布时间: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