Pretty simple, your .map
functor offers the opportunity for a reliable closure for the start time of each axios request, allowing calculation of time taken by subtraction in the requests' .then
callback.
var urls = ["http://req0.com","http://req1.com","http://req2.com"];
Promise.all(urls.map(e => {
let start = Date.now();
return axios.post(e, {test:'test'})
.then(value => ( { value, t: Date.now() - start} ));
}))
.then((timedValues) => {
let times = timedValues.map(x => x.t);
let values = timedValues.map(x => x.value);
console.log(times);
console.log(values);
});
If you wish to include the timing of errors, then it's only slightly more complicated:
var urls=["http://req0.com","http://req1.com","http://req2.com"];
Promise.all(urls.map(e => {
let t = Date.now();
return axios.post(e, {test:"test"})
.then(value => ( { outcome:'success', value, t:Date.now() - t} ))
.catch(error => ( { outcome:'error', error, t:Date.now() - t} ));
}))
.then((timedOutcomes) => {
let times = timedOutcomes.map(x => x.t);
let values = timedOutcomes.filter(x => x.outcome === 'success').map(x => x.value);
let errors = timedOutcomes.filter(x => x.outcome === 'error').map(x => x.error);
console.log(times);
console.log(values);
console.log(errors);
});