我正在使用一个异步函数,该函数将在搜索后返回一个值,该值在foreach完成之前返回。
async function accessSpreadsheet(orderId){
let tax="";
var doc = new GoogleSpreadsheet('54345u7iJzvl59oeyT_9np1Xd2_54654656');
await promisify(doc.useServiceAccountAuth)(creds);
const info = await promisify(doc.getInfo)();
const sheet = info.worksheets[0];
const rows =await promisify(sheet.getRows)({
offset:1
});
rows.forEach(row =>{
if(orderId == row.orderid){
tax=row.imei1;
}
});
return tax;
}
console.log(accessSpreadsheet("88280"));
我希望此功能具有tax
的值,但仅得到Promise { <pending> }
之类的未决承诺。我该如何纳税?