Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@homo-lorens
Me to Promise.allSettled():
"Just go and do all this shit and let me know what happened... whenever that is." -
hitko31454yUnless you can absolutely ignore errors and returned values, it's still a better idea to do something like
const [result1, result2, result3, ...] = await Promise.all([
p1.catch(err => ...),
p2.catch(err => ...),
p3.catch(err => ...),
...
])
With allSettled you can't assign returned values without referencing them by index, and you lose context (e.g. when you map an array to promises), which means you again need to reference items by index to log some meaningful info on errors. Also you're splitting item-level logic across multiple iterations, which makes your code much harder to understand. -
@hitko
I see what you mean, that's a good point when you want to be a bit more granular about who, what, where and etc came back.
In this case I'm doing a bunch of DB updates, all I want to know is who was successful and who wasn't. The successful responses I know what they'll look like so that's obvious by what is returned, and they tell me their id anyhow so I know who they are regardless of order.
If it fails I just note it as an error, log it, and notify the user that it didn't work and I have a process from there for them to retry and so on.
But good point. I like that method / might use it if I want to orchestrate a bit more.
This is the way.
joke/meme