我有一个看起来像这样的循环:
newThreadIds.map(async function(id) {
let thread = await API.getThread(id);
await ActiveThread.findOneAndUpdate({number: id}, {posts: thread.posts}, {upsert: true}).exec();
await Q.delay(1000);
});
问题是每次迭代都是异步执行的,我希望它们之间有 1 秒的延迟。我知道如何使用 Promise 来做到这一点,但它看起来很难看,我更愿意使用 async/await 和尽可能少的嵌套来做到这一点。