我在打字稿中有以下异步功能,看起来await不会阻止并按照我的预期生成所需的结果。打字稿异步等待不工作
async function getCroppedImgContent(origImgBuffer: Buffer) {
console.log("Inside setCroppedImgContent");
let croppedBuffer = await sharp(origImgBuffer)
.resize(4000, 4000)
.max()
.toBuffer();
console.log("After crop");
return croppedBuffer;
}
“作物后”不立即“内部setCroppedImgContent”后打印,但很多版本。看起来像等待不起作用。
问题是什么? – Amit
'sharp()。resize()。max()。toBuffer()'返回一个承诺,因为'await'只在你等待承诺时才真正有用。 – jfriend00
执行没有被阻塞在等待线上,结果稍后返回 – Nenad