-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path9.js
33 lines (29 loc) · 750 Bytes
/
9.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict';
var http = require('http');
var myPromise;
var p1;
var p2;
var p3;
myPromise = function (endpoint) {
return new Promise(function (resolve, reject) {
var body = '';
http.get(endpoint, function (res) {
res.setEncoding('utf8');
res.on('data', function (data) {
body += data;
});
res.on('end', function () {
resolve(body);
});
res.resume();
}).on('error', reject);
});
};
p1 = myPromise(process.argv[2]);
p2 = myPromise(process.argv[3]);
p3 = myPromise(process.argv[4]);
Promise.all([p1, p2, p3]).then(function (values) {
values.forEach(function (value) {
console.log(value);
});
});