Skip to content

@epikodelabs/streamix


@epikodelabs/streamix / Subscription

Type Alias: Subscription

Subscription = object

Defined in: projects/libraries/streamix/src/lib/abstractions/subscription.ts:15

Represents a subscription to a stream-like source.

A Subscription is returned from a stream's subscribe() method and represents an active connection between a producer and a consumer.

Responsibilities:

  • Tracks whether the subscription is active
  • Provides an idempotent mechanism to unsubscribe
  • Optionally executes cleanup logic on unsubscribe

Properties

id

readonly id: string

Defined in: projects/libraries/streamix/src/lib/abstractions/subscription.ts:17

Unique id for this subscription (correlates with subscriptionId)


unsubscribed

readonly unsubscribed: boolean

Defined in: projects/libraries/streamix/src/lib/abstractions/subscription.ts:27

Indicates whether the subscription has been terminated.

  • false - subscription is active
  • true - subscription has been unsubscribed and is inactive

This flag becomes true immediately when unsubscribe() is invoked for the first time.


onUnsubscribe()?

optional onUnsubscribe: () => MaybePromise

Defined in: projects/libraries/streamix/src/lib/abstractions/subscription.ts:59

Optional cleanup callback executed during unsubscription.

Intended usage:

  • Remove event listeners
  • Cancel timers or async tasks
  • Abort generators or observers

Guarantees:

  • Called at most once
  • Executed only after unsubscribed becomes true
  • May be synchronous or asynchronous

Any errors thrown by this callback are caught internally.

Returns

MaybePromise

Methods

unsubscribe()

unsubscribe(): any

Defined in: projects/libraries/streamix/src/lib/abstractions/subscription.ts:42

Terminates the subscription.

Semantics:

  • Idempotent: calling multiple times has no additional effect
  • Marks the subscription as unsubscribed synchronously
  • Executes cleanup logic (if provided) exactly once
  • Stream receivers may still get complete() as a cleanup signal

Errors thrown by cleanup logic are caught and logged.

Returns

any

A MaybePromise<void> that resolves when cleanup completes

Released under the MIT License.