迭代器处理异步

2019-11-05  本文已影响0人  立陶宛_d5a9

const callBack = function(fileName) {
return new Promise(function(resolve, reject) {
setTimeout(() => {
resolve()
}, 4000)
})
}
const gen = function*() {
let f1 = yield callBack()
console.log('a1')
let f2 = yield callBack()
console.log('a2')
}
function run(gen) {
let g = gen()
function next() {
let result = g.next()
if (result.done) return result.value
result.value.then(function() {
next()
})
}
next()
}
run(gen)

上一篇下一篇

猜你喜欢

热点阅读