Creates a new Counter instance.
The initial value of the counter. Default is 0
.
Decrements the counter by one.
The new value of the counter after decrementing.
Increments the counter by one.
The new value of the counter after incrementing.
Tests whether a subscriber is registered.
The subscriber function to check.
true if the subscriber is registered, false otherwise.
Protected
publishResets the counter to zero.
Registers a subscriber function to be called when the event is emitted.
If the subscriber is already registered, this method has no effect.
The subscriber function to call when the event is emitted.
Optional
options: SubscribableSubscribeOptionsOptional settings for the subscription.
A function that can be called to unsubscribe the subscriber, or null if the subscriber was already registered.
Unregisters a previously registered subscriber function.
If the subscriber is not registered, this method has no effect.
The subscriber function to remove.
Waits until the counter reaches the specified target value.
The value to wait for.
Optional
signal: null | AbortSignalAn optional AbortSignal to cancel the wait.
A simple counter that can be incremented or decremented, and allows waiting for it to reach a specific value.