退避时重试 [英] retryWhen with backoff

查看:120
本文介绍了退避时重试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http.get

return this.http.get(this.urlToBackend)
            .map((res: Response) => res.json())
            .retryWhen(errors =>
                errors
                    .zip(Observable.range(3, 15), (_, i) => i)
                    .flatMap(i => {
                        if (i >= 15) {
                            throw errors;
                        }
                        let t = (Math.pow(2, i)) * 1000;
                        return Observable.timer(t);
                    }))
            .catch((error: any) => this.handleError(error, false, 0, this.urlToBackend));

继续收到此错误:

TypeError: this.http.get(...).map(...).retryWhen is not a function
    at IOService.getUserDetails (http://localhost:4200/main.bundle.js:303:14)
    at NavirComponent.ngOnInit (http://localhost:4200/main.bundle.js:3328:24)
    at Wrapper_NavirComponent.ngDoCheck (/AppModule/NavirComponent/wrapper.ngfactory.js:22:53)
    at CompiledTemplate.proxyViewClass.View_AppWrapperComponent0.detectChangesInternal (/AppModule/AppWrapperComponent/component.ngfactory.js:100:28)
    at CompiledTemplate.proxyViewClass.AppView.detectChanges (http://localhost:4200/vendor.bundle.js:81933:14)
    at CompiledTemplate.proxyViewClass.DebugAppView.detectChanges (http://localhost:4200/vendor.bundle.js:82128:44)
    at CompiledTemplate.proxyViewClass.AppView.internalDetectChanges (http://localhost:4200/vendor.bundle.js:81918:18)
    at CompiledTemplate.proxyViewClass.View_AppWrapperComponent_Host0.detectChangesInternal (/AppModule/AppWrapperComponent/host.ngfactory.js:29:19)
    at CompiledTemplate.proxyViewClass.AppView.detectChanges (http://localhost:4200/vendor.bundle.js:81933:14)
    at CompiledTemplate.proxyViewClass.DebugAppView.detectChanges (http://localhost:4200/vendor.bundle.js:82128:44)
    at ViewRef_.detectChanges (http://localhost:4200/vendor.bundle.js:60587:20)
    at http://localhost:4200/vendor.bundle.js:41131:67
    at Array.forEach (native)
    at ApplicationRef_.tick (http://localhost:4200/vendor.bundle.js:41131:25)
    at ApplicationRef_._loadComponent (http://localhost:4200/vendor.bundle.js:41106:14)

推荐答案

尝试添加导入

import "rxjs/add/operator/mergeMap";

这篇关于退避时重试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆