2 ms·
return arr.map(ele => await axis.get(ele)); is not legal - the await has no corresponding async. You may have wanted to write return arr.map(async ele =>
by Arnavion 11y ago
return arr.map(ele => await axis.get(ele));
is not legal - the await has no corresponding async. You may have wanted to write
return arr.map(async ele => await axis.get(ele));
but that's the same as
return arr.map(ele => axis.get(ele));
(Assuming axis.get returns a promise.)
That is, it returns an array of promises of values, not a promise of an array of values like erlich's function.
erlich's example is correct, with the replacement of for-in with for-of.
Edit:
Also, a solution using Array.map() is not impossible:
return Promise.all(arr.map(ele => axis.get(ele)));
but this has different characteristics than the original function. The original ran the tasks in series whereas this runs them in parallel.