// Streaming lifecycle helper export function withStreamingLifecycle( setup: () => Promise, teardown: () => Promise, ) { let isCleaningUp = false; const cleanup = async () => { if (isCleaningUp) return; isCleaningUp = true; try { await teardown(); } finally { process.exit(0); } }; process.once('SIGINT', cleanup); process.once('SIGTERM', cleanup); return (async () => { await setup(); await new Promise(() => {}); // keep alive })(); }