我应该如何等待 bot.sendMessage()
循环内部?
也许我需要 await Promise.all
但我不知道我应该如何添加到 bot.sendMessage()
代码:
const promise = query.exec();
promise.then(async (doc) => {
let count = 0;
for (const val of Object.values(doc)) {
++count;
await bot.sendMessage(msg.chat.id, `💬 ${count} and ${val.text}`, opts);
}
}).catch((err) => {
if (err) {
console.log(err);
}
});
错误:
[eslint] Unexpected `await` inside a loop. (no-await-in-loop)
原文由 Saeed Heidarizarei 发布,翻译遵循 CC BY-SA 4.0 许可协议
如果您需要一次发送一条消息,那么您所拥有的就可以 了,根据文档,您可以像这样忽略 eslint 错误:
但是,如果发送消息不需要顺序,您应该改为这样做以最大化性能和吞吐量: