function async (generator) { return function() { const gen = generator.apply(this, arguments); return new Promise((resolve, reject) => { const step = function(key, data) { try { let res = gen[key](data); } catch(e) { resolve(e); } const {value, done} = res; if (done) { resolve(value); } else { return Promise.resolve(value).then(val => step('next', val), reason => step('throw', resaon)); } } step('next'); }); } }