【发布时间】:2018-11-22 06:56:41
【问题描述】:
我正在尝试实现 HTTP 轮询。期望每 5 分钟从 HTTP 轮询一次,或者我可以说在服务器上同步。如果失败,它不应该停止主题,而是应该重试 3 次,然后在 5 分钟后再次尝试。万一5分钟后也失败了,应该重试3分钟,场景继续进行。
我尝试的是一些东西。
const checkTimeForRestart$ = Rx.Observable.timer(5 * 60 * 1000, 5000)
.switchMap(() => Rx.Observable.of(axios.get(url)).retry(3));
// .map(response => console.log(`console here !! - ${response}`));
// .concatMap(val => of(`Delayed by: ${val}ms`).pipe(delay(val)));
checkTimeForRestart$.subscribe(
x => console.log(x),
error => console.error(`Error: ${error}`),
() => console.log(`Complete: fires when the observable completes`)
);
如果服务器未启动或存在连接问题,它不应该完成 observable,但应该尝试 3 次,然后在重做该过程后 5 分钟再次尝试。
【问题讨论】:
标签: rxjs