Skip to content

Commit 16defdb

Browse files
committed
fixup! fixup! feat(core): clear up integrations on dispose
1 parent a589811 commit 16defdb

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

packages/core/src/client.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,12 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
211211

212212
protected _promiseBuffer: PromiseBuffer<unknown>;
213213

214-
/** Cleanup functions to call on dispose */
214+
/**
215+
* Cleanup functions to call on dispose.
216+
*
217+
* NOTE: These callbacks are only invoked by subclasses whose `dispose()` implementation runs them
218+
* (currently only `ServerRuntimeClient`). The base `Client.dispose()` is a no-op and will not run them.
219+
*/
215220
protected _disposeCallbacks: (() => void)[];
216221

217222
/**
@@ -1152,6 +1157,11 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
11521157
/**
11531158
* Register a cleanup function to be called when the client is disposed.
11541159
* This is useful for integrations that need to clean up global state.
1160+
*
1161+
* NOTE: Registered callbacks are only executed by subclasses whose `dispose()` implementation
1162+
* runs them. At the moment that is only `ServerRuntimeClient` (and clients extending it). On the
1163+
* base `Client` (e.g. the browser client), `dispose()` is a no-op, so callbacks registered here
1164+
* will never be invoked.
11551165
*/
11561166
public registerCleanup(callback: () => void): void {
11571167
this._disposeCallbacks.push(callback);
@@ -1160,7 +1170,10 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
11601170
/**
11611171
* Disposes of the client and releases all resources.
11621172
*
1163-
* Subclasses should override this method to clean up their own resources.
1173+
* Subclasses should override this method to clean up their own resources, including invoking
1174+
* any callbacks registered via {@link Client.registerCleanup}. The base implementation is a
1175+
* no-op and does NOT execute registered cleanup callbacks.
1176+
*
11641177
* After calling dispose(), the client should not be used anymore.
11651178
*/
11661179
public dispose(): void {

0 commit comments

Comments
 (0)