function delay(wait) {
return new Promise((resolve, reject) => {
setTimeout(function () {
resolve(wait)
}, wait)
})
}
function* fun() {
var x1 = yield delay(1000)
console.log(x1)
var x2 = yield delay(4000)
console.log(x2)
}
var itor = fun()
itor.next().value.then(result => {
itor.next(result).value.then(result => {
itor.next(result)
})
})
function asyncFunction(generator) {
var itor = generator()
var next = (x) => {
const { value, done } = itor.next(x)
if (done) return
value.then(result => {
next(result)
})
}
next()
}
asyncFunction(function* fun() {
var x1 = yield delay(1000)
console.log(x1)
var x2 = yield delay(4000)
console.log(x2)
})