
在 Map 遍历中使用 async 函数
有时需要使用 Sleep 函数阻塞代码一段时间,该函数常规实现与调用方式如下: // Sleep Function const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))( // Usage async () => { await sleep(3000); } ); 但在 Array.prototype.map 中使用时,却有着错误的表现,具体如下: // code snippet 1 …