(
exitCode = 0,
reason: ExitReason = 'other',
options?: {
getAppState?: () => AppState
setAppState?: (f: (prev: AppState) => AppState) => void
},
)
| 334 | }) |
| 335 | |
| 336 | export function gracefulShutdownSync( |
| 337 | exitCode = 0, |
| 338 | reason: ExitReason = 'other', |
| 339 | options?: { |
| 340 | getAppState?: () => AppState |
| 341 | setAppState?: (f: (prev: AppState) => AppState) => void |
| 342 | }, |
| 343 | ): void { |
| 344 | // Set the exit code that will be used when process naturally exits. Note that we do it |
| 345 | // here inside the sync version too so that it is possible to determine if |
| 346 | // gracefulShutdownSync was called by checking process.exitCode. |
| 347 | process.exitCode = exitCode |
| 348 | |
| 349 | pendingShutdown = gracefulShutdown(exitCode, reason, options) |
| 350 | .catch(error => { |
| 351 | logForDebugging(`Graceful shutdown failed: ${error}`, { level: 'error' }) |
| 352 | cleanupTerminalModes() |
| 353 | printResumeHint() |
| 354 | forceExit(exitCode) |
| 355 | }) |
| 356 | // Prevent unhandled rejection: forceExit re-throws in test mode, |
| 357 | // which would escape the .catch() handler above as a new rejection. |
| 358 | .catch(() => {}) |
| 359 | } |
| 360 | |
| 361 | let shutdownInProgress = false |
| 362 | let failsafeTimer: ReturnType<typeof setTimeout> | undefined |
no test coverage detected