Skip to content

Instantly share code, notes, and snippets.

@EnixCoda
Created August 9, 2018 01:50
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EnixCoda/b2df85d5c56c1cf90cf113ce696e3bb8 to your computer and use it in GitHub Desktop.
Save EnixCoda/b2df85d5c56c1cf90cf113ce696e3bb8 to your computer and use it in GitHub Desktop.
Async/Await polyfill
module.exports = function decorate(func) {
const f = func()
return (function run(input) { f.next(input).then(run) })()
}
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)
@tomas-wrobel
Copy link

Awesome work! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment