$ show mcollina/close-with-grace
close-with-grace is a Node.js library that provides graceful shutdown handling for applications. It listens for system signals (SIGTERM, SIGINT, etc.) and process events (uncaughtException, unhandledRejection, beforeExit), giving applications a configurable timeout to perform cleanup operations before exiting. If the same signal occurs again during cleanup, it forces immediate termination. The library supports both callback and promise-based cleanup functions, custom logging, and the ability to skip specific events. It's designed as a simple, self-contained utility that can be easily integrated into any Node.js application needing reliable shutdown handling.
The LLM identified 1 files worth highlighting for reuse:
Implements a robust graceful shutdown mechanism for Node.js processes that handles multiple termination signals, provides configurable timeout, supports both callback and promise-based cleanup functions, and properly manages edge cases like second occurrences of events. The implementation demonstrates skill in handling the complexities of Node.js process lifecycle management while remaining self-contained and easily reusable. Key techniques include proper listener cleanup and re-registration, Promise.race for timeout handling, hybrid callback/promise support, and meticulous exit code management.