【发布时间】:2020-08-07 13:22:29
【问题描述】:
我有以下方法:
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) {}
}
问题是loadSkick()在.then执行的时候返回,但是值还是null因为下一个内部调用“return await response.blob();”尚未执行。
我只需要返回调用者一次的结果返回 await response.blob();被执行
【问题讨论】:
-
看来
this.graphClient.api('/me/drive/items/25647924903216B8%21227697').get(...)没有返回一个promise(因为你正在向它传递一个正常的回调)所以await在这种情况下没有做任何有用的事情。 -
我怎样才能让它按预期工作?
-
请发布指向 graphClient 库文档的链接。
-
文档:github.com/microsoftgraph/msgraph-sdk-javascript#documentation 但是我正在将此集成与 angular 一起使用:docs.microsoft.com/en-us/graph/tutorials/…
-
刚刚编辑了链接以直接访问文档