【发布时间】:2022-08-02 06:54:10
【问题描述】:
我必须在我的情况下实施池化,但我在正确实施我的所有条件时遇到了一些问题。
所以首先,我必须调用一个端点,在它返回成功后,调用另一个端点,直到它返回正确的响应(它总是返回成功/200/,但对我来说最重要的是响应,所以如果响应将是 {state : \'ready\'} 或者如果时间过去了(20 秒),我应该停止调用 api。
executeTest$(testCode: string, name: string): Observable<Test> {
let requestDelay = 500;
return this.testService.start({
body: {
code: {value: testCode},
name
}
}).pipe(
switchMap(body => {
return this.testStatus(body.name).pipe(
delay(500),
// and here I have problem to implement logic:
repeat this http until condition is met, so until response will be {state: \'ready\'}
I see that repeat when is deprecated and retry when is suitable for errors.
timeout(20000)
);
})
);
}
private testStatus(testId: string): Observable<Test> {
return this.http.get(apiUrl)
}