[英]Angular Rxjs repeatWhen: when all status are not COMPLETED
I want to retry(hit the same url upto 5 times with delay of 5sec) the same URL if I am not received all status are 'COMPLETED' in Angular Service file我想重试(点击相同的 url 最多 5 次,延迟为 5 秒)相同的 URL 如果我没有收到 ZC31C335EF37283C451B 服务文件中的所有状态都是“已完成”
[
{
"data": [
//SET OF OBJECTS
],
"status": "COMPLETED"
},
{
"data": [
//SET OF OBJECTS
],
"status": "NO_DATA_FOUND"
}
]```
try this尝试这个
this.http.get().pipe(
map(res => {
res.array.forEach(el => {
if (el.status !== "completed") {
//error will be catched by retryWhen
throw res;
}
})
return res;
}),
retry(5),
retryWhen(errors => errors.pipe(delay(1000)))
)
Not sure what your code looks like, but I think this approach should work:不确定您的代码是什么样的,但我认为这种方法应该有效:
src$.pipe(
retryWhen(
errSbj => errSbj.pipe(
delay(/* ... */),
take(5),
// Until it receives a `COMPLETED` status
takeUntil(statusCompleted$)
)
)
)
When statusCompleted$
emits, the entire stream will complete
.当statusCompleted$
发出时,整个 stream 将complete
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.