(elapsedMs = 0)
| 2 | const MAX_WAIT_INTERVAL = 2000; |
| 3 | |
| 4 | export function exitGracefully(elapsedMs = 0) { |
| 5 | // Check if there are any pending operations |
| 6 | const hasPendingOperations = checkForPendingOperations(); |
| 7 | |
| 8 | if (hasPendingOperations && elapsedMs < MAX_WAIT_INTERVAL) { |
| 9 | // Wait a bit longer if there are pending operations |
| 10 | setTimeout( |
| 11 | () => exitGracefully(elapsedMs + STEP_WAIT_INTERVAL), |
| 12 | STEP_WAIT_INTERVAL, |
| 13 | ); |
| 14 | } else { |
| 15 | // Exit immediately if no pending operations |
| 16 | process.exit(0); |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | function checkForPendingOperations(): boolean { |
| 21 | // Check for active handles and requests using internal Node.js methods |
no test coverage detected