Skip to content

Documentation / @andrew_l/graceful / onShutdown

Function: onShutdown() ​

Call Signature ​

onShutdown(handler): CancelCallback

Gracefully terminate application's modules on shutdown.

Parameters ​

handler ​

Handler

Async or sync function which handles shutdown.

Returns ​

CancelCallback

Call Signature ​

onShutdown(name, handler): CancelCallback

Gracefully terminate application's modules on shutdown.

Parameters ​

name ​

string

Name of the handler.

handler ​

Handler

Async or sync function which handles shutdown.

Returns ​

CancelCallback

Call Signature ​

onShutdown(dependencies, handler): CancelCallback

Gracefully terminate application's modules on shutdown.

Parameters ​

dependencies ​

string[]

Which handlers should be processed first.

handler ​

Handler

Async or sync function which handles shutdown.

Returns ​

CancelCallback

Call Signature ​

onShutdown(name, dependencies, handler): CancelCallback

Gracefully terminate application's modules on shutdown.

Parameters ​

name ​

string

Name of the handler.

dependencies ​

string[]

Which handlers should be processed first.

handler ​

Handler

Async or sync function which handles shutdown.

Returns ​

CancelCallback

Example ​

ts
// This will called after http server close
onShutdown('mongoose', ['http-server'], async () => {
  console.info('Graceful: mongodb connection.');
  await mongoose.disconnect();
});

onShutdown('http-server', async () => {
  console.info('Graceful: http server.');
  await httpServer.close();
});