Skip to main content

Class: ScopedSubscriptionManager

Defined in: electron/events/ScopedSubscriptionManager.ts:33

Utility for managing event subscriptions within a scoped lifecycle.

Remarks​

Tracks disposers for typed event bus subscriptions (and arbitrary cleanup functions) so they can be disposed together. Prevents leaked listeners when services register numerous handlers across the app lifecycle.

Constructors​

Constructor​

new ScopedSubscriptionManager(): ScopedSubscriptionManager;

Returns​

ScopedSubscriptionManager

Properties​

disposers​

private readonly disposers: Set<() => void>;

Defined in: electron/events/ScopedSubscriptionManager.ts:34

Accessors​

activeCount​

Get Signature​

get activeCount(): number;

Defined in: electron/events/ScopedSubscriptionManager.ts:39

Returns the number of currently tracked disposers.

Returns​

number

Methods​

track()​

track(disposer: () => void): () => void;

Defined in: electron/events/ScopedSubscriptionManager.ts:53

Tracks a disposer function and returns a wrapped variant that removes itself from the tracked set upon invocation.

Parameters​

disposer​

() => void

Function responsible for removing a subscription or performing cleanup.

Returns​

Wrapped disposer that can be invoked manually; repeat invocations are ignored to maintain idempotency.

() => void


onTyped()​

onTyped<EventMap, K>(
bus: TypedEventBus<EventMap>,
event: K,
listener: TypedEventListener<EventMap, K>): () => void;

Defined in: electron/events/ScopedSubscriptionManager.ts:81

Registers a typed event listener and tracks the corresponding disposer.

Type Parameters​

EventMap​

EventMap extends object

Event map maintained by the typed event bus.

K​

K extends string

Specific event key being subscribed to.

Parameters​

bus​

TypedEventBus<EventMap>

Typed event bus to subscribe to.

event​

K

Event name to listen for.

listener​

TypedEventListener<EventMap, K>

Listener invoked when the event is emitted.

Returns​

Disposer that removes the listener when invoked.

() => void


clearAll()​

clearAll(options?: DisposeOptions): void;

Defined in: electron/events/ScopedSubscriptionManager.ts:101

Disposes all tracked listeners and cleanup functions.

Parameters​

options?​

DisposeOptions = {}

Disposal behaviour configuration. Use this to attach an error callback or suppress aggregate errors.

Returns​

void