【发布时间】:2019-07-01 11:26:24
【问题描述】:
我有一个函数调用一个函数,该函数又订阅 HTTP 调用。我知道订阅不会返回 async await 期望的承诺,但有没有办法可以限制执行,直到返回数据。
我尝试过使用异步等待,但没有运气 我可以将要执行的代码放入订阅中 但我不想这样做,因为我的功能不是为此而设计的(试图遵循单一责任原则)
async function a () {
await subscription_return();
code to be executed after subscription has got the data
}
subscription_return(){
this.http.getDataFromService().subscribe((response) => {});
}
【问题讨论】:
-
好吧,您可能不应该在其他函数中订阅。只需返回 observable 并在您的第一个函数中订阅。
标签: angular asynchronous async-await rxjs