Skip to content

Instantly share code, notes, and snippets.

@jspenc72
Created February 5, 2017 23:58
Show Gist options
  • Save jspenc72/0e38235539b207e527e9203eb3109034 to your computer and use it in GitHub Desktop.
Save jspenc72/0e38235539b207e527e9203eb3109034 to your computer and use it in GitHub Desktop.
bluebird_example.js
var Promise = require("bluebird");
var request = require('request');
function getData(){
return new Promise(function (resolve, reject) {
console.log('inside promise');
request('http://alphaapi.readymed.com/api/projects/', function (error, response, body) {
console.log('got json',body.length);
reject(true);
if(error){
reject(error)
}else{
resolve(body);
}
});
})
}
var promise = getData();
promise
.then(function (res){
console.log('promise has resolved');
console.log('inside first then');
})
.then(function (res){
console.log('inside second then');
})
.catch(function(err){
console.error('Promise was rejected',err);
})
.done(function (res){
console.log('promise is completed');
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment