promise和yield配合使用
2019-12-05 本文已影响0人
凡凡的小web
延迟几秒执行
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()