update
This commit is contained in:
22
ts/cli/helpers/lifecycle.ts
Normal file
22
ts/cli/helpers/lifecycle.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
// Streaming lifecycle helper
|
||||
export function withStreamingLifecycle(
|
||||
setup: () => Promise<void>,
|
||||
teardown: () => Promise<void>,
|
||||
) {
|
||||
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
|
||||
})();
|
||||
}
|
Reference in New Issue
Block a user