预期下面的方法是Observable,它需要来自promise函数的一些数据才能继续执行。
async function observableFunc(): Observable<string> {
const response = await promiseFunc()
return anotherObservableFunc(response)
}
这将引发错误,因为异步函数应该返回承诺。
I tried to use .toPromise()
but then I can’t do something using .pipe()
later on like this:
observableFunc().pipe(...)
一个开发人员打算在这里做什么? 🤔
您必须将诺言转变为可观察的
我假设anotherObservableFunc返回一个可观察的。
尝试这个
以这种方式创造新的承诺
您也可以等待几秒钟尝试这样
You can use
from
, which converts aPromise
(among other things) to anObservable
: