Skip to content

Function: createSubscription()

createSubscription(onUnsubscribe?): Subscription

Defined in: abstractions/subscription.ts:41

Creates a new subscription with optional cleanup logic.

This factory function initializes a Subscription object that manages its own state. It provides a robust mechanism for a stream consumer to stop listening for values and to perform custom teardown tasks.

Parameters

onUnsubscribe?

() => any

An optional callback function to be executed when the unsubscribe method is called. This is useful for custom resource cleanup.

Returns

Subscription

A new Subscription instance.

Released under the MIT License.