Created
April 7, 2017 06:47
-
-
Save hzhangxyz/7a78e7ff8ffcd4a744a761074ac541c3 to your computer and use it in GitHub Desktop.
convert callback function to async function
This file contains 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
//convert callback function to async function | |
var asyncalize = (func) => | |
function(){ | |
console.log(func) | |
return new Promise( | |
(callback)=>func(...arguments,callback) | |
) | |
} | |
asyncalize((a,b)=>setTimeout(b,a))(1000).then(()=>console.log("hello")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment