Rxjs 重试不会导致在重试Observable时重试ajax调用
基于Rxjs 重试不会导致在重试Observable时重试ajax调用,rxjs,reactive-programming,redux-observable,Rxjs,Reactive Programming,Redux Observable,基于redux observable我有一个史诗: export const someEpic = action$ => { return action$.pipe( ofType('FETCH_DATA'), switchMap(({ payload: { filter, bookingCenter } }) => { return concat( of(searchInProgress()), from(
redux observable
我有一个史诗:
export const someEpic = action$ => {
return action$.pipe(
ofType('FETCH_DATA'),
switchMap(({ payload: { filter, bookingCenter } }) => {
return concat(
of(searchInProgress()),
from(
ApiManager.call('/v1/some-data', {
method: 'GET',
schema: false,
params: {
term: filter,
bookingCenter,
},
})
).pipe(
map(response => {
if (!response) throw 'No result';
return response;
}),
map(({ _embedded }) => updateResult(_embedded)
)
).pipe(retry(2));
})
);
};
如您所见,我有一个重试操作符。基本上,若服务器并没有返回响应,我抛出一个错误,然后重试
然而,它只是部分工作,即在控制台中,我看到searchInProgress
操作被调度,但是使用从创建的第二个可观察对象不会再次执行
apimager.call
正在返回常规fetch
API承诺
我做错了什么?解决方案是使用延迟
,这将延迟从承诺
创建可观察对象:
defer(() =>
ApiManager.call('/v1/some-data', {
method: 'GET',
schema: false,
params: {
term: filter,
bookingCenter,
limit: 500,
},
})
)
你能做一个stackblitz演示吗?