From 236583c8b00fef05ee5be7cc1bf97e5343d70feb Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 23 Sep 2026 19:15:42 +0200 Subject: [PATCH] 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 --- packages/cultmesh-ts/src/realtime-quic-native.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/cultmesh-ts/src/realtime-quic-native.ts b/packages/cultmesh-ts/src/realtime-quic-native.ts index c3f13ca2..4020f3ce 100644 --- a/packages/cultmesh-ts/src/realtime-quic-native.ts +++ b/packages/cultmesh-ts/src/realtime-quic-native.ts @@ -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)