Skip to content

Instantly share code, notes, and snippets.

@hzhangxyz
Created April 7, 2017 06:47
Show Gist options
  • Save hzhangxyz/7a78e7ff8ffcd4a744a761074ac541c3 to your computer and use it in GitHub Desktop.
Save hzhangxyz/7a78e7ff8ffcd4a744a761074ac541c3 to your computer and use it in GitHub Desktop.
convert callback function to async function
//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