return result;
/*
return new Promise((resolve, reject) => {
resolve(result);
});
*/
先后用了两类写法,最后反应过来async函数默认返回的就是Promise对象,所以直接返回结果就可以啊。
Making setTimeout an async/await function
no need to pass anything to callback func but just resolve
async function wait(ms) {
return new Promise(resolve => {
setTimeout(resolve, ms);
});
}
async function doRequests(uris) {
for(const uri of uris) {
await fetch(uri);
await wait(1000);
}
}
网友评论