I am trying to execute a function after the response is completed. How can I do that without setTimeout()?
I am uploading large files, if the file is small it is working fine, but if it is large the waiting time is not enaught.
<code> this.orderTestService.orderObservable$
.pipe(untilDestroyed(this))
.subscribe((response) => {
if(response){
setTimeout( () => {
this.service.getDocuments(); }, 1000 );
}
}
});
</code>
<code> this.orderTestService.orderObservable$
.pipe(untilDestroyed(this))
.subscribe((response) => {
if(response){
setTimeout( () => {
this.service.getDocuments(); }, 1000 );
}
}
});
</code>
this.orderTestService.orderObservable$
.pipe(untilDestroyed(this))
.subscribe((response) => {
if(response){
setTimeout( () => {
this.service.getDocuments(); }, 1000 );
}
}
});
4
You can use finalize operator, this operator executes your function when the observable completes.
<code>this.orderTestService.orderObservable$
.pipe(
untilDestroyed(this),
finalize(() => {
this.service.getDocuments();
})
)
.subscribe((response) => {
if (response) {
// Handle successful response
}
});
</code>
<code>this.orderTestService.orderObservable$
.pipe(
untilDestroyed(this),
finalize(() => {
this.service.getDocuments();
})
)
.subscribe((response) => {
if (response) {
// Handle successful response
}
});
</code>
this.orderTestService.orderObservable$
.pipe(
untilDestroyed(this),
finalize(() => {
this.service.getDocuments();
})
)
.subscribe((response) => {
if (response) {
// Handle successful response
}
});
2