Dispatcher
See in:
Reading time:2 min read
The EventDispatcher is responsible for calling EventSubscribers, checking middlewares, and handling errors of each emitted event.
It's used by every EventBus through EventBus#emit(), and can be replaced at runtime with EventBus#setDispatcher().
When to override
| ✅ Override if you want to... | ❌ Don't override if you want to... |
|---|---|
| Change how subscribers are dispatched (batching, throttling, etc). | Add/remove event middlewares only. You can do that from the dispatcher's middleware list. |
| Add custom logic that modify execution (instrumentation, retries, etc). | Add/change error consumers only. You can do that from the dispatcher's error handler. |
| Tune runtime behavior like sync timeout or async concurrency. The base dispatchers implementations already allow that. |
Overriding
Creation
Create a custom dispatcher by either:
- Extending
BasicSyncEventDispatcherorBasicAsyncEventDispatcher(recommended, less work). - Implementing
EventDispatcher.
import { } from '@nyx-discord/djs';
class extends {}Registration
Set your dispatcher on any bus:
.(.());You can do this for built-in buses too, for example the client bus:
const = .((: ) => { /** options */ });
.()
.(.());Dependencies
The dispatcher has two core dependencies you can customize:
Edit on GitHub
Last updated on
