我试图在响应完成后执行一个函数。如果没有 setTimeout() 我该如何做到这一点? 我正在上传大文件,如果文件很小,则工作正常,但如果文件很大,则等待时间不够。
this.orderTestService.orderObservable$
.pipe(untilDestroyed(this))
.subscribe((response) => {
if(response){
setTimeout( () => {
this.service.getDocuments(); }, 1000 );
}
}
});
您可以使用 finalize 运算符,该运算符在可观察对象完成时执行您的函数。
this.orderTestService.orderObservable$
.pipe(
untilDestroyed(this),
finalize(() => {
this.service.getDocuments();
})
)
.subscribe((response) => {
if (response) {
// Handle successful response
}
});