Created
August 9, 2018 01:50
-
-
Save EnixCoda/b2df85d5c56c1cf90cf113ce696e3bb8 to your computer and use it in GitHub Desktop.
Async/Await polyfill
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function decorate(func) { | |
const f = func() | |
return (function run(input) { f.next(input).then(run) })() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const decorate = require('./polyfill.js') | |
// code after transform // | raw async/await code: | |
function* likeAsyncAwait () { // | async function realAsyncAwait () { | |
const result = yield asyncCall() // | const result = await asyncCall() | |
return result // | return result | |
} // | } | |
// async operation, return a promise | |
function asyncCall() { | |
return Promise.resolve(true) | |
} | |
module.exports = decorate(likeAsyncAwait) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome work! Thanks!