Send Mrs. Sari’s runners to the market one by one (for…of with await), all at once (Promise.all), or through a forEach: real timers show when they are all…
Why it matters
This is one of the most common causes of "why is loading so slow", and one of the easiest to fix: swapping an await in a loop for Promise.all can cut seconds to hundreds of milliseconds. But forEach with an async callback waits for nothing, and thousands of requests at once can be turned away by the server.
The key idea
await in a loop means queueing; map plus Promise.all means together
Common mistakes
await in a loop for tasks that do not depend on each other It forces a queue, and the times add up. Use await Promise.all(daftar.map(fn)) when they do not depend on each other; go one by one only when a step needs the result before it.
await inside forEach forEach ignores the promises its callback returns and waits for nothing, even with an await in front of it. Use for…of (one by one) or map + Promise.all (together).
Try it in this playground
for…of: watch the next one wait its turn The chilli only leaves once the egg is back.
Promise.all: all three leave together Run it until it prints: the total is the slowest one.
forEach: 'selesai' prints before anything is back selesai: [] at 0 ms.
Hit the server's limit: 429 Server at 2, then send all three at once.