Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Keep observation work off the response critical path
When an observe-only or shadow check does not determine the response, do not await it in the response path. Run it as explicitly handled best-effort work, or use a lifecycle-safe background mechanism when completion must outlive the request.
Bad example
| 1 | async function respond(load: () => Promise<string>, observe: () => Promise<void>): Promise<string> { |
| 2 | const [content] = await Promise.all([load(), observe()]); |
| 3 | return content; |
| 4 | } |
Explanation (EN)
The content still waits for the observation request, so a slow optional dependency changes user-visible response latency even though it cannot change the payload.
Objašnjenje (HR)
Sadržaj i dalje čeka mjerenje, pa spora neobavezna ovisnost mijenja vrijeme odgovora iako ne određuje sadržaj.
Good example
| 1 | async function respond( |
| 2 | load: () => Promise<string>, |
| 3 | observe: () => Promise<void>, |
| 4 | reportFailure: () => void, |
| 5 | ): Promise<string> { |
| 6 | void observe().catch(reportFailure); |
| 7 | return load(); |
| 8 | } |
Explanation (EN)
In a long-lived server, bounded observation runs independently and rejection is handled. A controlled pending-observation test should prove that the real response completes before observation settles.
Objašnjenje (HR)
U dugotrajnom serverskom procesu vremenski ograničeno mjerenje radi odvojeno uz obradu greške. Test s namjerno nedovršenim mjerenjem treba potvrditi da HTTP odgovor stiže prije njega.
Notes (EN)
Apply when a feature explicitly promises measurement without affecting the delivered response. Check latency as part of that promise, not only payload and headers. Promise.all provides concurrency but still waits for every member. Verify runtime lifetime and a finite timeout before detaching work. A concurrency test that merely proves serialization starts is insufficient to prove the HTTP response is independent.
Bilješke (HR)
Primjenjuje se kad je svrha promjene mjerenje bez utjecaja na isporučeni odgovor. Provjeri latenciju uz sadržaj i headere. Promise.all radi paralelno, ali čeka svaki član. Prije odvajanja rada provjeri životni vijek procesa i vremensko ograničenje.
Exceptions / Tradeoffs (EN)
Await authorization decisions, required audit persistence, transactional steps and other work whose result or completion is required before delivery. In runtimes that can stop after a response, use the supported background lifetime or a durable queue when completion is required. Do not replace awaiting with void alone when rejection can occur.
Iznimke / Tradeoffi (HR)
Čekaj autorizacijske odluke, obavezni zapis audita, transakcijske korake i drugi rad potreban prije isporuke. Ako runtime može stati nakon odgovora, za obavezan završetak koristi podržani mehanizam za pozadinski rad ili trajni red. Sam void ne obrađuje odbijeni promise.