Created
August 20, 2016 15:33
-
-
Save aaronblondeau/30d6323449c79d7f7309baca0009ab72 to your computer and use it in GitHub Desktop.
Promise.coroutine (No coroutine - just promises)
This file contains hidden or 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'); | |
var fs = require('fs'); | |
request_promise = Promise.promisify(request); | |
writeFile_promise = Promise.promisify(fs.writeFile); | |
request_promise('https://s3.amazonaws.com/aaronblondeau/widgets/widgets.json') | |
.then((response, body) => { | |
var data = JSON.parse(response.body); | |
return writeFile_promise('./widgets.json', JSON.stringify(data.widgets)); | |
}) | |
.then(() => { | |
console.log("Done") | |
}) | |
.catch((err) => { | |
// This a bit better for catching errors | |
console.error(err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment