美文网首页
迭代器处理异步

迭代器处理异步

作者: 立陶宛_d5a9 | 来源:发表于2019-11-05 10:06 被阅读0次

    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)

    相关文章

      网友评论

          本文标题:迭代器处理异步

          本文链接:https://www.haomeiwen.com/subject/rohsbctx.html