Angular 然后()承诺块不等待内部等待
我有以下方法:Angular 然后()承诺块不等待内部等待,angular,promise,Angular,Promise,我有以下方法: this.skickPlayerService.loadSkick().then( (skick) => { var skickBlob = skick as Blob; }, (error) => {} ); 异步方法调用如下所示: async loadSkick(): Promise<any> { try { return await this.graphClient .api('/me/drive/items/2
this.skickPlayerService.loadSkick().then(
(skick) => {
var skickBlob = skick as Blob;
},
(error) => {}
);
异步方法调用如下所示:
async loadSkick(): Promise<any> {
try {
return await this.graphClient
.api('/me/drive/items/25647924903216B8%21227697')
.get(async (err, res) => {
if (err) {
return;
}
return await fetch(res['@microsoft.graph.downloadUrl']).then(
async function (response) {
return await response.blob(); // I need the call to wait until this is executed
}
);
});
} catch (error) {}
}
async loadSkick():Promise{
试一试{
返回等待此。graphClient
.api(“/me/drive/items/25647924903216B8%21227697”)
.get(异步(err,res)=>{
如果(错误){
返回;
}
返回等待获取(res['@microsoft.graph.downloadUrl'])。然后(
异步函数(响应){
return wait response.blob();//我需要调用等待,直到执行为止
}
);
});
}捕获(错误){}
}
问题是loadSkick()在执行.then时返回,但该值仍然为null,因为下一个内部调用“return wait response.blob();”尚未执行
我只需要返回调用者一次,返回的结果等待响应。blob();从文档中执行,看起来应该可以:
async loadSkick(): Promise<any> {
const res = await this.graphClient
.api('/me/drive/items/25647924903216B8%21227697')
.get();
const response = await fetch(res['@microsoft.graph.downloadUrl']);
return response.blob();
}
async loadSkick():Promise{
const res=等待此消息。graphClient
.api(“/me/drive/items/25647924903216B8%21227697”)
.get();
const response=wait fetch(res['@microsoft.graph.downloadUrl']);
返回response.blob();
}
调用
loadSkick()
的调用方必须将返回的承诺与wait
或.then()
一起使用才能获得最终结果。似乎this.graphClient.api('/me/drive/items/25647924903216B8%21227697')。get(…)
不返回承诺(因为您正在传递一个正常的回调)因此,await
在这种情况下没有任何用处。我如何才能让它像预期的那样工作?请发布一个指向graphClient库文档的链接。文档:但是我正在使用与angular的集成:只需编辑链接即可直接访问文档。你太棒了。谢谢