Closed MalQaniss closed 2 years ago
Essentially, yes.
There's a helper in the IOHelpers
module for this specific use-case, called waitAll(..)
. You'd use it in your example like this:
const planetsNums = ['1','2']
const getPlanet = num => IO(() => fetch(`https://swapi.dev/api/planets/${num}`).then(response => response.json()))
const data = await waitAll( ...planetsNums.map(getPlanet) ).run();
console.log(data);
If we let's say want to send parallel requests with "Promise.all" would this be a fine way: