runWireServe method
- required Future<
void> serve(- WireServeServer server
- void onDiagnostic(
- String line
- void onReady()?,
Runs the wire-serve loop until serve completes (stdin EOF, SIGTERM
handling, or a fatal transport error — the transport decides). An
in-flight run is aborted and given a bounded settle window first;
the transcript persists, then normal teardown runs. Returns the
process exit code (0; 3 when an ownership lease blocks the boot).
onReady fires after the boot (and its lease gate) succeeded but
before the transport starts — the WS host prints its one stdout
startup line there, so a parent never reads a startup line for a
serve that refuses to boot. Decomposed into one-decision helpers —
each stays at cyclomatic 3 or under, the CRAP ratchet floor for
code CI cannot cover (the CRAP lcov excludes integration tests,
and only an integration run can drive this boot).
Implementation
Future<int> runWireServe({
required Future<void> Function(WireServeServer server) serve,
void Function(String line)? onDiagnostic,
void Function()? onReady,
}) async {
final server = _wireServeServer(onDiagnostic);
_wireHostInteraction(server);
final pumpSub = _wirePump(server);
final runtime = await _wireServeBoot(pumpSub);
if (runtime == null) {
return 3;
}
onReady?.call();
try {
await serve(server);
} finally {
await _wireServeTeardown(server, pumpSub, runtime);
}
return 0;
}