Function delay(wait) {return Promise((resolve, reject) => {setTimeout(function () {resolve(wait)}, Wait)})} // Generator function 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 => { Async /await function asyncFunction(generator) {var itor = generator() var next = (x) => { const { value, Done} = itor.next(x) if (done) return value.then(result => {next(result)})} next()} // Function asyncFunction(function*) fun() { var x1 = yield delay(1000) console.log(x1) var x2 = yield delay(4000) console.log(x2) })Copy the code