Generator yield 迁移 await/async
es6 异步使用了await 和 async,老代码 使用了 generator 和yield ,迁移需要利用到 co.wrap 函数
var co = require('co');
function* oldF() {
return yield new Promise(function (resolve, reject) {
setTimeout(function () {
resolve(2)
}, 500)
})
}
async function doit() {
console.log(1)
var p = await co.wrap(oldF)();
console.log(p)
console.log(3)
}
doit();
参考文档:https://github.com/koajs/convert/blob/master/index.js
https://github.com/tj/co