Performance: Promise.race and Promise.allSettled
MEDIUM IMPACT
This concept affects how asynchronous operations impact page responsiveness and resource usage during concurrent tasks.
await Promise.race([task1(), task2(), task3()]); // resolves or rejects as soon as one task settles
await Promise.allSettled([task1(), task2(), task3()]); // waits for all tasks to finish
| Pattern | Async Wait Time | UI Responsiveness | Resource Usage | Verdict |
|---|---|---|---|---|
| Promise.allSettled for first result | Long (waits all) | Low (delayed) | High (all tasks run fully) | [X] Bad |
| Promise.race for first result | Short (first settles) | High (fast response) | Moderate (tasks still run) | [OK] Good |
| Promise.all for all success | Medium (waits all success) | Medium (may reject early) | High (may retry) | [!] OK |
| Promise.allSettled for all results | Long (waits all) | High (stable UI) | Moderate (no retries) | [OK] Good |