Skip to content

Instantly share code, notes, and snippets.

@amio
Created February 9, 2016 07:59
Show Gist options
  • Save amio/32bd7c54f23cc68343c7 to your computer and use it in GitHub Desktop.
Save amio/32bd7c54f23cc68343c7 to your computer and use it in GitHub Desktop.
syncify.js
// 1. fn's last argument should be a callback
// 2. the syncified function returns an array, which is the arguments for that callback.
function syncify (fn) {
let doing = true
return function (...args) {
let result = undefined
fn(...args, (...callbackArgs) => {
result = callbackArgs
doing = false
})
while (doing) {}
return result
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment