Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Avoid awaiting inside a loop; batch with Promise.all or a single set-based query
Batch independent repeated I/O or use bounded concurrency after verifying ordering, resource limits and failure behavior.
Bad example
| 1 | for (const id of ids) { |
| 2 | await this.repo.update(id, payload); |
| 3 | } |
Explanation (EN)
Serializing independent operations can add latency, but concurrency needs an explicit resource and failure contract.
Objašnjenje (HR)
Good example
| 1 | await Promise.all(ids.map((id) => this.repo.update(id, payload))); |
| 2 | // or a single: UPDATE ... WHERE id IN (:ids) |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
For independent repeated I/O, prefer a set-based operation or measured bounded concurrency. Preserve required order, transaction behavior, resource limits and cancellation/error policy.
Exceptions / Tradeoffs (EN)
Sequential awaits are correct for dependent steps, ordered side effects, rate limits or driver restrictions. Unbounded Promise.all can exhaust a pool or continue writes after one promise rejects.