Last active
May 2, 2017 19:38
-
-
Save rdsubhas/68da4df50a4f0684f6d2 to your computer and use it in GitHub Desktop.
es7-async-await
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 = Promise.promisifyAll(require('request')); | |
var url1='http://httpbin.org/', url2=url1, url3=url1, url4=url1; | |
async function foo() { | |
var res1 = await request.getAsync(url1); | |
var res2 = await request.getAsync(url2); | |
var res3 = await request.getAsync(url3); | |
var res4 = await request.getAsync(url4); | |
return "whew all done"; | |
} | |
// use that function somewhere | |
foo().then(function(message) { | |
console.log("success!", message); | |
}).catch(function(err) { | |
console.log("error!", err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment