Performance: Promise chaining
MEDIUM IMPACT
Promise chaining affects the responsiveness and smoothness of asynchronous operations in the browser or Node.js event loop.
doTask1()
.then(() => doTask2())
.then(() => doTask3())
.then(() => {
console.log('All done');
});doTask1().then(() => {
return doTask2().then(() => {
return doTask3().then(() => {
console.log('All done');
});
});
});| Pattern | Microtask Queue Complexity | Event Loop Blocking | Error Handling | Verdict |
|---|---|---|---|---|
| Nested .then callbacks | High (deep nesting) | Higher blocking due to nested microtasks | Harder to catch errors | [X] Bad |
| Flat promise chaining | Low (linear chain) | Minimal blocking, smoother event loop | Simpler error propagation | [OK] Good |