withCleanup
Wraps a client with a cleanup function, making it Disposable.
Plugin authors can use this to register teardown logic (e.g. closing
connections or clearing timers) that runs when the client is disposed.
If the client already implements Symbol.dispose, the existing dispose
logic is chained so that it runs after the new cleanup function.
Type Parameters
| Type Parameter | Description |
|---|---|
TClient extends object | The type of the original client. |
Parameters
| Parameter | Type | Description |
|---|---|---|
client | TClient | The client to wrap. |
cleanup | () => void | The cleanup function to run when the client is disposed. |
Returns
Disposable & TClient
A new client that extends TClient and implements Disposable.
Example
Register a cleanup function in a plugin that opens a WebSocket connection.