My current scenario involves a specific use-case:
There is a service that queues calculation tasks assigned with a certain ID. I have set up an observable to monitor the status of the service. When the ID is still in the queue, the query result is true
(indicating that the task has not been calculated yet). Once the query result is false
, it means that the task has been completed.
I am searching for a way for the observable to emit only when the returned value is false
. I have attempted to achieve this using .skipWhile
and .filter
, but have not been successful in getting the desired outcome.
private calc = new Subject<T>();
calculate(id: number): Observable<T> {
this.calcService.searchID(id).filter((x: boolean) => x == false)
.subscribe((dat: boolean) => {
this.calc.next(T);
});
return this.calc.share();
}
or
calculate(id: number): Observable<T> {
this.calcService.searchID(id).skipWhile((x: boolean) => x == true)
.subscribe((dat: boolean) => {
this.calc.next(T);
});
return this.calc.share();
}
(Apologies for the use of == true/false)
I hope someone can provide me with some guidance. I am using RxJS 6.
Edit:
Apologies for the oversight. this.calcService.searchID(id)
is actually an HTTP request. And with each request, it returns a boolean value. Therefore, I may receive false
after 20 requests or after 100. The timing depends on how fast the calculation is processed by the service. So, I need a way to either wait for the response to be false
or retry the request until false
is obtained.