Created
February 9, 2016 07:59
-
-
Save amio/32bd7c54f23cc68343c7 to your computer and use it in GitHub Desktop.
syncify.js
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
// 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