@@ -15,7 +15,10 @@ const shutdownConfigs: ShutdownConfig[] = [];
15
15
16
16
let isShuttingDown = false ;
17
17
18
- async function startShutdown ( ) {
18
+ /**
19
+ * Start a graceful API shutdown.
20
+ */
21
+ export async function shutdown ( ) : Promise < void > {
19
22
if ( isShuttingDown ) {
20
23
return ;
21
24
}
@@ -67,26 +70,30 @@ function registerShutdownSignals() {
67
70
SHUTDOWN_SIGNALS . forEach ( sig => {
68
71
process . once ( sig , ( ) => {
69
72
logger . info ( `Shutting down... received signal: ${ sig } ` ) ;
70
- void startShutdown ( ) ;
73
+ void shutdown ( ) ;
71
74
} ) ;
72
75
} ) ;
73
76
process . once ( 'unhandledRejection' , error => {
74
77
logger . error ( error , 'unhandledRejection' ) ;
75
78
logger . error ( 'Shutting down... received unhandledRejection.' ) ;
76
- void startShutdown ( ) ;
79
+ void shutdown ( ) ;
77
80
} ) ;
78
81
process . once ( 'uncaughtException' , error => {
79
82
logger . error ( error , 'uncaughtException' ) ;
80
83
logger . error ( 'Shutting down... received uncaughtException.' ) ;
81
- void startShutdown ( ) ;
84
+ void shutdown ( ) ;
82
85
} ) ;
83
86
process . once ( 'beforeExit' , ( ) => {
84
87
logger . error ( 'Shutting down... received beforeExit.' ) ;
85
- void startShutdown ( ) ;
88
+ void shutdown ( ) ;
86
89
} ) ;
87
90
}
88
91
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 {
90
97
registerShutdownSignals ( ) ;
91
98
shutdownConfigs . push ( ...configs ) ;
92
99
}
0 commit comments