NitroCompletionBatch class

Shared-port demux for one library's @nitroNativeAsync completions.

Every message a Dart isolate receives costs one embedder task (~10 µs in a Flutter build), whichever port it targets. The C++ side (nitro_completion_batch.h) therefore delivers completions to this one port as [id, value, id, value, ...] and holds any that arrive before ack so they travel as one message. A lone completion still goes out at once.

Implemented types

Constructors

NitroCompletionBatch({required int bind(int batchPort), required void ack(int batchPort), required int arm(int batchPort), required void disarm(int batchPort), required int poll(int id, Pointer<Uint8> out, int giveUp)})

Properties

ack → void Function(int batchPort)
<lib>_nitro_ack(batchPort), sent after every handled batch.
final
arm → int Function(int batchPort)
<lib>_nitro_arm(id) → claimed — try to claim the one shared spin slot. Returns 1 if this isolate claimed it, 0 if another isolate owns it (the one process-global batch has a single slot). A non-claiming caller must NOT spin — see armSpin/spinPoll.
final
bind → int Function(int batchPort)
<lib>_nitro_bind(batchPort) → id, reserved per call.
final
disarm → void Function(int batchPort)
<lib>_nitro_disarm(id) — release a claim whose native call threw before dispatching a worker (no completion will ever free it otherwise).
final
hashCode → int
The hash code for this object.
no setterinherited
nativePort → int
no setter
pendingCount → int
no setter
poll → int Function(int id, Pointer<Uint8> out, int giveUp)
<lib>_nitro_poll(id, out, giveUp) → state — one spin iteration.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
sendPort → SendPort
The batch port as a SendPort (tests feed it without native code).
no setter

Methods

armSpin(int id) → bool
Tries to claim the native spin slot for id. Call right before the native call, only when single-in-flight (see spinPoll). Returns false if another isolate already owns the one shared slot — the caller must then NOT spin (go straight to the port wait), or it would read the owner's payload.
disarmSpin(int id) → void
Releases a claim taken by armSpin when the native call threw before it could dispatch a worker (so no completion will ever free the slot).
forget(int id) → void
Drops a call (timeout); a late completion is ignored on arrival.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
register(void onComplete(dynamic raw)) → int
Reserves an id for one call; the native side posts its result to it. onComplete must not throw.
spinPoll(int id, int capUs) → List?
Busy-polls the armed slot (issue #57), capped at capUs µs. Returns a one-element [raw] when the completion lands off-port — no port message, no OS wake — or null when it parks, leaving the normal port callback to deliver it. Single-in-flight only.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited