DEV Community

Toolloom
Toolloom

Posted on • Originally published at toolloom.com on

Don't Wait Serially for Parallel Tasks

If you have three independent API calls or database queries, resist the urge to await them one after the other. That makes your total execution time the sum of all three. If they don't depend on each other, fire them off simultaneously using Promise.all() (in JavaScript, or similar concurrency patterns in other languages). For example, const [user, posts] = await Promise.all([fetchUser(), fetchPosts()]); This dramatically reduces latency, making your application feel much snappier because you only wait for the slowest task to complete, not the cumulative total.

Top comments (0)