Skip to content

Instantly share code, notes, and snippets.

@jmav
Created April 19, 2016 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmav/07b16d0d19357d8cf503f661ef3ad396 to your computer and use it in GitHub Desktop.
Save jmav/07b16d0d19357d8cf503f661ef3ad396 to your computer and use it in GitHub Desktop.
Q sample - deffered
var Q = require('q');
function function_name(argument) {
var deferred = Q.defer();
if (err) {
deferred.reject(err);
} else {
deferred.resolve(imageLocation(id, type, 'thumb'));
}
return deferred.promise;
}
// Call fb
function_name(argument)
.then(function (result) {
return res.json(result);
})
.catch(function (error) {
var errString = error.message || error || '';
errString = errString.substr(0, 15);
return res.badRequest({
status: 'error',
err: errString
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment