637080
/**
* This example prints :
*
* -----------
* -----------
* -----------
* -----------
* Resolved HTTP Call
* 0
* Resolved HTTP Call
* 2
* Resolved HTTP Call
* 0
* Resolved HTTP Call
* 1
* Resolved HTTP Call
* 2
* Resolved HTTP Call
* 1
* Resolved HTTP Call
* 1
* Resolved HTTP Call
* 0
* Resolved HTTP Call
* 2
*
* Fix the `Tester` class in order to have it print :
*
* -----------
* Resolved HTTP Call
* 0
* Resolved HTTP Call
* 1
* Resolved HTTP Call
* 2
* -----------
* Resolved HTTP Call
* 0
* [...]
*
* Feel free to implement/modify any methods that are relevant. DO NOT modify the `getUrl` method.
*/
const http = require('http')
class Tester {
constructor(firstUrl, secondUrl, thirdUrl) {
console.info('-----------')
for(let i = 0; i < 3; i++) {
console.info('-----------')
this.run([firstUrl, secondUrl, thirdUrl])
}
}
run(urls) {
urls.forEach((url, index) => {
this.getUrl(url, index)
.then(this.print)
})
}
getUrl(url, index) {
return new Promise((resolve, reject) => {
let timeout = Math.floor(Math.random() * (500 - 3000 + 1)) + 3000
setTimeout(() => {
http.get(url, (res) => {
console.info('Resolved HTTP Call')
resolve(index)
});
}, timeout)
})
}
print(value) {
console.info(value)
}
}
const tester = new Tester(
'http://httpbin.org/ip',
'http://httpbin.org/user-agent',
'http://httpbin.org/headers')