美文网首页
promise和yield配合使用

promise和yield配合使用

作者: 凡凡的小web | 来源:发表于2019-12-05 17:20 被阅读0次

延迟几秒执行
function mySleep(s) {
return new Promise(resolve => this.scheduleOnce(resolve, s));
}
使用
async function () {
await sleep(10)
console.log('10')
})

高级

async function test () {
            var show = myShow();   //须将函数声明为变量使用此方法

            show.next()

            await sleep(10)
            show.next()

            await sleep(47)
            self.nextPage()
        }

      function* myShow() {
            self.playSound(s[0])
            childs[2].frame([res.g新人设2, res.g新人设3], 0.35, 14)

            yield 
            self.playSound(s[1])
            childs[2].frame([res.g新人设4, res.g新人设41], 0.35)
        }
test()

相关文章

网友评论

      本文标题:promise和yield配合使用

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