Created
February 5, 2017 23:58
-
-
Save jspenc72/0e38235539b207e527e9203eb3109034 to your computer and use it in GitHub Desktop.
bluebird_example.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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