Add CultMeshQuicNativeRuntime.retain(): a synchronous extra reference

A caller that already holds a live runtime instance (the QUIC realtime
provider, handing a reference to each newly accepted peer) needs one more
reference without crossing an async boundary. `open()` itself has no I/O
to await, but being `async` still forces every caller through a microtask
hop; `retain()` just increments the shared refcount and returns `this`,
synchronously, so the caller stays inside the same turn.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-23 19:15:42 +02:00
commit 236583c8b0

View file

@ -296,6 +296,19 @@ export class CultMeshQuicNativeRuntime {
return CultMeshQuicNativeRuntime.shared;
}
/**
* Takes one more reference on this already-open runtime, synchronously —
* unlike `open()`, this never awaits a runtime-open call, so a caller
* already holding a live instance (a provider handing a reference to a
* newly accepted peer) can attach it in the same synchronous turn instead
* of crossing a microtask boundary that would leave the event a caller is
* mid-dispatching unowned until the next tick.
*/
retain(): CultMeshQuicNativeRuntime {
CultMeshQuicNativeRuntime.refCountValue += 1;
return this;
}
/**
* Drops one reference; closes the shared runtime once none remain. Refuses
* a release when no reference is outstanding. The bridge header (section 4)