我有一系列的方法依賴於其他方法的完成。等待觀察完成
process1(data: string) : Observable<string> {
this.dataservice.process(data).subscribe(
(response) => {
return response.data;
}
);
}
main(data: string) : string {
var process1Data: string = process1(data);
// I would like to wait for process1 method to complete before running process2
// I do not want to include process2 inside subscribe of process1 because I have to make few more method calls
var process2Data: string = process2(process1Data);
var process3Data: string = process3(process2Data);
...
}
如何在調用next方法(process2,process3)之前等待observable完成? (類似像等待在C#)
是的,它會這樣工作,但我將不得不使所有主要的調用方法異步太。有沒有可能實現這一點,而不是主要的異步?如果需要,我可以讓process1異步。 – developer