Skip to content

Instantly share code, notes, and snippets.

@Kinzi
Created October 13, 2017 06:48
Show Gist options
  • Save Kinzi/7fc89bc94cea62f2b4b1e566023a290c to your computer and use it in GitHub Desktop.
Save Kinzi/7fc89bc94cea62f2b4b1e566023a290c to your computer and use it in GitHub Desktop.
Basic q promises nodejs
var q = require('q');
// Single promise function
var promiseFunction = function(){
var deferred = q.defer();
deferred.resolve();
return deferred.promise;
};
// several promises
var promises = [];
promises.push(
promiseFunction()
//.then(funciton(res){
// do something
//})
);
q.all(promises)
.then(function(result){
console.log(result);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment