Skip to content

Instantly share code, notes, and snippets.

@gaurang847
Created June 19, 2019 19:21
Show Gist options
  • Save gaurang847/b2191b7a88547aeaa715f6f0be0268ee to your computer and use it in GitHub Desktop.
Save gaurang847/b2191b7a88547aeaa715f6f0be0268ee to your computer and use it in GitHub Desktop.
//normally calling an async function
get_value_from_DB(function(err, data){
if(err)
//handle error
else
//work with data
})
//converting async function to promise and calling it
new Promise(function(resolve, reject){
get_value_from_DB(function(err, data){
if(err) reject(err);
else resolve(data);
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment