gpt4 book ai didi

javascript - Observables "retryWhen"延迟

转载 作者:数据小太阳 更新时间:2023-10-29 06:10:17 25 4
gpt4 key购买 nike

如何在 retryWhen 中设置延迟?

import 'rxjs/add/operator/retry';
import 'rxjs/add/operator/retrywhen';

...

constructor(http: Http) {

var headers = new Headers();
headers.append('Content-Type', 'text/plain');
http.post('https://mywebsite.azurewebsites.net/account/getip', "", { headers: headers })
.retryWhen(errors => {
return errors.delay(1000); // errors is not a function
})
(event) => {
// handle events
this.ip = event.json();
},
(error) => {
console.error(error);
toastr.error('No connection to server. Please reload the page!')

}
);
}

我收到错误:errors is not a function

最佳答案

import {Http, Headers, Response} from '@angular/http';

http.get('http://jsonplaceholder.typicode.com/posts/1/commentsss')
.retryWhen(e => e.scan<number>((errorCount, err) => {
if (errorCount >= 10) {
throw err;
}
return errorCount + 1;
}, 0).delay(1000))
.subscribe(r => console.log(`Sub: ${r}`))

重试 10 次,延迟 1 秒。

plnkr

关于javascript - Observables "retryWhen"延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39146958/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com