We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
async 函数的实现原理,就是将 Generator 函数和自动执行器,包装在一个函数里
function spawn(genF) { return new Promise(function(resolve, reject) { const gen = genF(); function step(nextF) { let next; try { next = nextF(); } catch (e) { return reject(e); } if (next.done) { return resolve(next.value); } Promise.resolve(next.value).then( function(v) { step(function() { return gen.next(v); }); }, function(e) { step(function() { return gen.throw(e); }); } ); } step(function() { return gen.next(undefined); }); }); }
The text was updated successfully, but these errors were encountered:
同样的效果
function spawn(genF) { return new Promise(function(resolve, reject) { const gen = genF() try { while (true) { const next = gen.next() if (!next.done) continue resolve(next.value) break } } catch (e) { return reject(e); } }) }
这是不是简单多了 谬,理解错题意了
function spawn(genF) { const gen = genF() return function next (v) { return new Promise((resolve, reject) => { try { const result = gen.next(v) if (result.done) { return resolve(result.value) } return Promise.resolve(result.value).then(next).then(resolve, reject) } catch (e) { reject(e) } }) } () }
Sorry, something went wrong.
No branches or pull requests
async 函数的实现原理,就是将 Generator 函数和自动执行器,包装在一个函数里
The text was updated successfully, but these errors were encountered: