Skip to content

Commit 6148dca

Browse files
committed
fixup! feat(core): clear up integrations on dispose
1 parent 8664a61 commit 6148dca

2 files changed

Lines changed: 13 additions & 14 deletions

File tree

packages/core/src/client.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,6 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
212212

213213
protected _promiseBuffer: PromiseBuffer<unknown>;
214214

215-
/**
216-
* Cleanup functions to call on dispose.
217-
*
218-
* NOTE: These callbacks are only invoked by subclasses whose `dispose()` implementation runs them
219-
* (currently only `ServerRuntimeClient`). The base `Client.dispose()` is a no-op and will not run them.
220-
*/
221-
protected _disposeCallbacks: (() => void)[];
222-
223215
/**
224216
* Initializes this client instance.
225217
*
@@ -232,7 +224,6 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
232224
this._outcomes = {};
233225
this._hooks = {};
234226
this._eventProcessors = [];
235-
this._disposeCallbacks = [];
236227
this._promiseBuffer = makePromiseBuffer(options.transportOptions?.bufferSize ?? DEFAULT_TRANSPORT_BUFFER_SIZE);
237228

238229
if (options.dsn) {
@@ -1182,13 +1173,12 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
11821173
* Register a cleanup function to be called when the client is disposed.
11831174
* This is useful for integrations that need to clean up global state.
11841175
*
1185-
* NOTE: Registered callbacks are only executed by subclasses whose `dispose()` implementation
1186-
* runs them. At the moment that is only `ServerRuntimeClient` (and clients extending it). On the
1187-
* base `Client` (e.g. the browser client), `dispose()` is a no-op, so callbacks registered here
1188-
* will never be invoked.
1176+
* NOTE: This is a no-op in the base `Client` class. Subclasses like `ServerRuntimeClient`
1177+
* override this method to actually register and execute cleanup callbacks.
11891178
*/
1179+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
11901180
public registerCleanup(callback: () => void): void {
1191-
this._disposeCallbacks.push(callback);
1181+
// No-op in base class - subclasses override to implement cleanup registration
11921182
}
11931183

11941184
/**

packages/core/src/server-runtime-client.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export interface ServerRuntimeClientOptions extends ClientOptions<BaseTransportO
3131
export class ServerRuntimeClient<
3232
O extends ClientOptions & ServerRuntimeClientOptions = ServerRuntimeClientOptions,
3333
> extends Client<O> {
34+
private _disposeCallbacks: (() => void)[] = [];
35+
3436
/**
3537
* Creates a new Edge SDK instance.
3638
* @param options Configuration options for this SDK.
@@ -154,6 +156,13 @@ export class ServerRuntimeClient<
154156
return id;
155157
}
156158

159+
/**
160+
* @inheritDoc
161+
*/
162+
public override registerCleanup(callback: () => void): void {
163+
this._disposeCallbacks.push(callback);
164+
}
165+
157166
/**
158167
* Disposes of the client and releases all resources.
159168
*

0 commit comments

Comments
 (0)