@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
readonlyid:string
Defined in: projects/libraries/streamix/src/lib/abstractions/subscription.ts:17
Unique id for this subscription (correlates with subscriptionId)
unsubscribed
readonlyunsubscribed:boolean
Defined in: projects/libraries/streamix/src/lib/abstractions/subscription.ts:27
Indicates whether the subscription has been terminated.
false- subscription is activetrue- subscription has been unsubscribed and is inactive
This flag becomes true immediately when unsubscribe() is invoked for the first time.
onUnsubscribe()?
optionalonUnsubscribe: () =>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
unsubscribedbecomestrue - May be synchronous or asynchronous
Any errors thrown by this callback are caught internally.
Returns
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