Open jiaochunxiao opened 4 years ago
// 给定p1, p2, p3,实现一个方法依次输出 1,2, 3, done
var p1 = function () {
return new Promise((resolve) => {
setTimeout(() => {
resolve(1);
}, 1000);
})
}
var p2 = function () {
return new Promise((resolve) => {
setTimeout(() => {
resolve(2);
}, 1000);
})
}
var p3 = function () {
return new Promise((resolve) => {
setTimeout(() => {
resolve(3);
}, 1000);
})
}
async function fn(arr) {
for (let index = 0; index < arr.length; index++) {
console.log(await arr[index]());
}
}
fn([p1,p2,p3]).then(() => {console.log('done1')});
function createQueue(tasks) {
return new Promise(async (resolve, reject) => {
for (let i = 0; i < tasks.length; i++) {
await tasks[i]();
}
resolve('done');
})
}
给定p1, p2, p3,实现一个方法依次输出 1,2, 3, done