We are making an http request in Angular that returns some data containing a boolean that indicates whether or not the data has been completely processed. We would like to emit the incomplete data from the first http response and continue making http requests until processed is true. We also would like to avoid making duplicate http requests if the first response returns with processed true. We are using the retryBackoff library, which if I understand correctly is just retryWhen with a delay under the hood.
Here's a sample from the code we're working on:
const crashDetails$ = combineLatest(crashId$, database$)
.pipe(switchMap(([crashId, database]) => {
return this._crashDetailsService.getCrashDetails({crashId, database});
});
const crashDetailsWithRetry$ = crashDetails$
.pipe(
tap(crashDetails => {
if (!crashDetails.processed) {
throw new Error('Still processing, retry if able');
}
}),
retryBackoff(retryOptions)
);
return merge($crashDetails, crashDetailsWithRetry$);
The problem is 2 requests get made in the case processed is true.
I tried adding share() and shareReplay(1) to crashDetails$, but this causes crashDetailsWithRetry$ to stop working. Is there an easy way to achieve what we want, or should I create a new subject and custom retry logic to handle this case?
Thanks!