I’m currently trying to process HTTP Post requests in sequence, additionally trying to repeat each failed request until it succeeds (that is a requirement) and then and only then to continue with processing other requests. My code looks like this for now (it not working as it should, retryWhen is not used properly, I am aware of that, it’s used just as a starting point reference):
JavaScript
x
14
14
1
2
subject
3
.pipe(
4
concatMap(async request => await this._sendPostRequest(request)),
5
retryWhen(errors =>
6
errors.pipe(
7
tap(error => this._logger.error('error sending request', error)),
8
delayWhen(() => timer(5000))
9
)
10
)
11
)
12
.subscribe();
13
14
Advertisement
Answer
You’re close!
Just attach your retry to the promise rather than the concatenated stream as a whole.
JavaScript
1
9
1
subject.pipe(
2
concatMap(request => defer(() => sendPostRequest(request)).pipe(
3
retryWhen(error$ => error$.pipe(
4
tap((error) => console.warn('error sending request', error)),
5
delay(1000)
6
))
7
))
8
).subscribe();
9