fix(shutdown): arm the teardown timer before the callback that clears it #44

Merged
chrnx merged 1 commits from fix/teardown-timer-ordering into develop 2026-08-18 14:18:49 +00:00
Owner

Closes #20.

runTeardown declared finish above the timer it clears. The reference held only because every caller is asynchronous — correct by timing, not by construction, which is exactly what #20 asked to remove from this file. closeApp twenty lines below already arms its timer first and carries a comment explaining why that direction is safe; this makes the two agree.

No behaviour change. 416 vitest / 10 Deno / 6 Bun / edge all green.

Closes #20. `runTeardown` declared `finish` above the `timer` it clears. The reference held only because every caller is asynchronous — correct by timing, not by construction, which is exactly what #20 asked to remove from this file. `closeApp` twenty lines below already arms its timer first and carries a comment explaining why that direction is safe; this makes the two agree. No behaviour change. 416 vitest / 10 Deno / 6 Bun / edge all green.
chrnx added 1 commit 2026-08-18 14:16:37 +00:00
fix(shutdown): arm the teardown timer before the callback that clears it
CI / dco (pull_request) Successful in 4s
CI / runtimes (bun) (pull_request) Successful in 14s
CI / build (pull_request) Successful in 25s
CI / runtimes (deno) (pull_request) Successful in 17s
CI / runtimes (edge) (pull_request) Successful in 11s
198e62944f
`runTeardown` declared `finish` above the `timer` it clears, so the
reference held only because every caller — the timer's own callback and
`teardown.run().then()` — happens to be asynchronous. That is correct by
timing rather than by construction, which is what #20 asked to remove from
this file; `closeApp` twenty lines below already arms its timer first and
carries a comment explaining why that direction is the safe one.

Reversing the order here leaves both shutdown paths resting the same forward
reference on the same guarantee: setTimeout cannot invoke its callback
synchronously. No behaviour changes.

Closes #20

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
chrnx merged commit 6672185ba2 into develop 2026-08-18 14:18:49 +00:00
Sign in to join this conversation.