# Shutting down cleanly

Often you'll want to run your app in a way that it can terminate cleanly and give it time to finish doing its work before exiting. This is common if you manually terminate it (CTRL + C), send it a kill signal like `kill -INT 1234` or if the underlying pod/container/host is stopping.

In these situations your app should finish processing the any messages its read from the queue and not read any more, allowing it to exit gracefully.

To do this, hooking into the process signals and calling **dispose** on the bus is the cleanest way.

### Example handling SIGINT

```typescript
import { Bus, BusInstance } from '@node-ts/bus-core'

let bus: BusInstance

const start = async () => {
  bus = Bus.configure().initialize()
  await bus.start()
}

/**
* Listens for a signal interrupt and gracefully disposes the bus
* before exiting.
*/
const listenForSigInt = () => {
  process.once('SIGINT', async () => {
    console.log('Received SIGINT, shutting down...')
    if (bus) {
      await bus.dispose()
    }
  })
}

listenForSigInt()
start().catch(console.err)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bus.node-ts.com/installing/shutting-down-cleanly.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
