closingset
v0.1.0
Published
Every process deserves a proper closing set. Tiny graceful-shutdown manager: register cleanup handlers, run them LIFO on SIGINT/SIGTERM with a hard timeout.
Maintainers
Readme
closingset
Every process deserves a proper closing set — not a kill -9 mid-drop.
Tiny, dependency-free graceful-shutdown manager: register cleanup handlers,
and on SIGINT/SIGTERM they run once, LIFO (last opened, first closed),
under a hard timeout so a stuck handler can't keep the process alive forever.
import closingset from "closingset";
const set = closingset({ timeout: 10_000, log: console.error });
const server = app.listen(8317);
set.add("http", () => new Promise((r) => server.close(r)));
const db = await connect();
set.add("db", () => db.end()); // closes BEFORE http (LIFO)
// manual shutdown also works:
await set.close(0);Handlers that throw are logged and the exit code becomes 1; the set always plays to the end.
MIT © wobondar
