kStreamDrainMaxMicrotasks top-level constant
Maximum number of microtask yields the synchronous-FFI streaming wrappers
use to drain queued NativeCallable.listener callbacks before deciding
whether to force-close the controller (FLUTTER-IOS-001).
Rationale: rac_*_stream*_proto are synchronous FFI calls — they block the
main isolate, so every NativeCallable.listener invocation made during the
call queues onto the event loop instead of running. After the FFI returns,
we must yield a bounded number of times to let those queued callbacks
(including the terminal one) drain before closing the controller; otherwise
subscribers receive an empty stream even though native emitted events.
The bound is intentionally small (we exit early as soon as a terminal event
has been observed via sawTerminalEvent). 4 ticks is empirically enough
for the bursty TTS/STT/VLM/LLM callback patterns we ship today. Bumping
this only adds latency on misbehaving backends that never send a terminal
event — increase if you observe tail-event loss in tests.
Implementation
const int kStreamDrainMaxMicrotasks = 4;