import { findStreamFlushMillis, Task } from "batch-cluster";
const minReliable = await findStreamFlushMillis({
processFactory: () => spawn("perl", [exiftoolPath, "-stay_open", "True", "-@", "-"]),
versionCommand: "-ver\n-execute\n",
pass: "{ready}",
fail: "{ready}",
exitCommand: "-stay_open\nFalse\n",
taskFactory: (i) => {
const cmds = ["-json\n/clean.jpg\n-execute\n", "-validate\n/warn.jpg\n-execute\n"];
return new Task(cmds[i % cmds.length], (stdout) => stdout);
},
});
const streamFlushMillis = minReliable + 5; // additive headroom for load spikes
Find the minimum reliable
streamFlushMillisvalue for the given child process on the current hardware.Returns the minimum
streamFlushMillisvalue that produced zeronoTaskDataevents across all confirmation trials. Because the confirmation phase already tests the worst case observed during discovery, the returned value is a near-ceiling, not a mean — similar in spirit to how TCP's RTO (RFC 6298) isSRTT + 4*RTTVARrather than a flat multiplier. Callers needing additional headroom for transient load spikes should add a small additive constant (e.g.result + 5), since OS scheduling jitter is an additive phenomenon independent of the baseline value.