function ajax (url) { return new Promise(function (resolve, reject) { let xhr = new XMLHttpRequest() xhr.open('GET', url) xhr.responseType = 'json' xhr.onload = function () { if (this.status + '' === '200') { resolve(this.response) console.log(this.response) } else { reject(new Error(this.responseText)) console.log(this.responseText) } } xhr.send() }) }function * main () { try { const users = yield ajax('/ajaxTest.js') console.log(users) const post = yield ajax('/ajaxPost.js') console.log(post) }catch (e) { console.log(e) }}function coo (generator) { const g = generator() function handleResult (data) { if (data.done) return data.value.then(result => { handleResult(g.next(data)) }, function (error) { g.throw(error) })}handleResult(g.next())}coo(main)