Skip to content

Commit 58a8a7f

Browse files
committed
feat: expose graceful shutdown method
1 parent bf2a903 commit 58a8a7f

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/shutdown-handler/index.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ const shutdownConfigs: ShutdownConfig[] = [];
1515

1616
let isShuttingDown = false;
1717

18-
async function startShutdown() {
18+
/**
19+
* Start a graceful API shutdown.
20+
*/
21+
export async function shutdown(): Promise<void> {
1922
if (isShuttingDown) {
2023
return;
2124
}
@@ -67,26 +70,30 @@ function registerShutdownSignals() {
6770
SHUTDOWN_SIGNALS.forEach(sig => {
6871
process.once(sig, () => {
6972
logger.info(`Shutting down... received signal: ${sig}`);
70-
void startShutdown();
73+
void shutdown();
7174
});
7275
});
7376
process.once('unhandledRejection', error => {
7477
logger.error(error, 'unhandledRejection');
7578
logger.error('Shutting down... received unhandledRejection.');
76-
void startShutdown();
79+
void shutdown();
7780
});
7881
process.once('uncaughtException', error => {
7982
logger.error(error, 'uncaughtException');
8083
logger.error('Shutting down... received uncaughtException.');
81-
void startShutdown();
84+
void shutdown();
8285
});
8386
process.once('beforeExit', () => {
8487
logger.error('Shutting down... received beforeExit.');
85-
void startShutdown();
88+
void shutdown();
8689
});
8790
}
8891

89-
export function registerShutdownConfig(...configs: ShutdownConfig[]) {
92+
/**
93+
* Register shutdown handlers for different API components.
94+
* @param configs - Array of shutdown configurations
95+
*/
96+
export function registerShutdownConfig(...configs: ShutdownConfig[]): void {
9097
registerShutdownSignals();
9198
shutdownConfigs.push(...configs);
9299
}

0 commit comments

Comments
 (0)