# new NanoDispatch(timeoutopt)
Handles the subscription to and processing of database change events from a Nano database, notifying observers when documents are created, updated, or deleted
Dispatcher for Nano database change events
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
timeout |
number
|
<optional> |
5000 | Timeout in milliseconds for change feed requests |
Example
```typescript
// Create a dispatcher for a Nano database
const db = server.db.use('my_database');
const adapter = new NanoAdapter(db);
const dispatch = new NanoDispatch();
// The dispatcher will automatically subscribe to changes
// and notify observers when documents change
```
Methods
# async protected changeHandler(error, response, headersopt) → {Promise.<void>}
Handles the response from the Nano changes feed, processes the changes, and notifies observers about document changes
Processes database change events
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
error |
RequestError
|
null
|
Error object if the request failed |
|
response |
The changes response from Nano |
||
headers |
any
|
<optional> |
Response headers (unused) |
A promise that resolves when all changes have been processed
Promise.<void>
# close() → {Promise.<void>}
Stops the dispatcher and cleans up any active subscriptions or resources
Closes the dispatcher
A promise that resolves when the dispatcher has been closed
Promise.<void>
# async protected initialize() → {Promise.<void>}
Sets up the continuous changes feed subscription to the Nano database and handles reconnection attempts if the connection fails
Initializes the dispatcher and subscribes to database changes
A promise that resolves when the subscription is established
Promise.<void>