Skip to content

Instantly share code, notes, and snippets.

@mkamakura
Last active June 9, 2016 06:42
Show Gist options
  • Save mkamakura/67c873968e991ea80baffa0f23cf56bd to your computer and use it in GitHub Desktop.
Save mkamakura/67c873968e991ea80baffa0f23cf56bd to your computer and use it in GitHub Desktop.
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