Answer the question
In order to leave comments, you need to log in
How to run a subject in interception after a while?
I have an intersepsh that catches outgoing requests and puts them in a list. As long as the list is not empty, the spinner is turned on. How to add requests to the list - only if the answer from them did not come within 2 seconds?
intercept(
req: HttpRequest<any>,
next: HttpHandler
): Observable<HttpEvent<any>> {
this.requests.push(req);
this.spinnerService.isLoading.next(true);
return new Observable((observer) => {
next
.handle(req)
.pipe(debounceTime(1000))
.subscribe(
(event) => {
if (event instanceof HttpResponse) {
this.removeRequest(req);
observer.next(event);
}
},
(err) => {
this.removeRequest(req);
}
);
});
}
this.requests.push(req);
this.spinnerService.isLoading.next(true);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question