Last active
June 9, 2016 06:42
-
-
Save mkamakura/67c873968e991ea80baffa0f23cf56bd to your computer and use it in GitHub Desktop.
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
const rp = require('request-promise'); | |
const options = { | |
uri: 'https://ntp-a1.nict.go.jp/cgi-bin/time', | |
transform: (body, response, resolveWithFullResponse) => { | |
return new Promise((resolve, reject) => { | |
if (response.statusCode !== 200) reject(); | |
resolve(response.body); | |
}); | |
} | |
} | |
const promiseList = [0,1,2,3,4].map(() => rp(options)); | |
console.log('start'); | |
Promise.all(promiseList).then((data) => console.log('done:', data)); | |
console.log('...'); | |
/* | |
$ node request-promise-simple-sample.js | |
start | |
... | |
done: [ 'Thu Jun 9 15:19:55 2016 JST\n', | |
'Thu Jun 9 15:19:55 2016 JST\n', | |
'Thu Jun 9 15:19:55 2016 JST\n', | |
'Thu Jun 9 15:19:55 2016 JST\n', | |
'Thu Jun 9 15:19:55 2016 JST\n' ] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment