Menu

1 / 4

Array.fromAsync vs Promise.all: Same Array on a Good Day, a Crashed Node Process on a Bad One

JavaScript in Plain English - Medium·Santosh Yadav·6 days ago
#fHSrTvv0
Reading 0:00
15s threshold

Member-only story

Array.fromAsync vs Promise.all: Same Array on a Good Day, a Crashed Node Process on a Bad One

Array.fromAsync awaits one value at a time. That makes it right for pages and streams, and risky for requests you already started.

Santosh Yadav

12 min read5 hours ago

Press enter or click to view image in full size

Wrap this in a try/catch and it looks safe:

try {

const users = await Array.fromAsync(ids.map(fetchUser));

render(users);

} catch (err) {

showError(err);

}

Now let the second request fail fast while the first one is still loading. On Node 26.13.1 the process exits with code 1 and the catch block never runs. Change Array.fromAsync to Promise.all and the same failure lands in the catch 23 ms in.

That difference is what this post on Array.fromAsync vs Promise.all is about. Both turn a list of async work into one array, and when everything succeeds they hand you the same result. They differ in when they start listening.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.