const setTime = (val, m) =>
new Promise((resolve) => {
setTimeout(() => {
resolve(val)
}, m)
}).then((e) => {
console.log(e);
return e;
})
const func1 = () => setTime(1, 2000)
const func2 = () => setTime(2, 1000)
const func3 = () => setTime(3, 2000)
//实现一个函数
function exectudePromise(list = []) {
return new Promise((resolve) => {
const newList = [];
function *func(){
for(let i = 0, len = list.length; i < len; i++){
const val = yield list[i]().then(a => res.next(a));
newList.push(val);
};
resolve(newList)
}
var res = func();
res.next();
})
}
exectudePromise([func1, func2, func3]).then((res) => {
console.log('end')
console.log(res)
})
console