Skip to content

Counter

Defined in: packages/async/src/synchro/counter.ts:17

A counter primitive that can be incremented, decremented, and waited upon.

const counter = new Counter(0);
// Increment the counter
counter.increment();
// Decrement the counter
counter.decrement();
// Wait for the counter to reach a specific value
await counter.wait(5);

new Counter(initialValue?): Counter

Defined in: packages/async/src/synchro/counter.ts:29

Creates a new Counter instance.

number = 0

The initial value of the counter. Default is 0.

Counter

get value(): number

Defined in: packages/async/src/synchro/counter.ts:33

number

decrement(): number

Defined in: packages/async/src/synchro/counter.ts:58

Decrements the counter by one.

number

The new value of the counter after decrementing.


increment(): number

Defined in: packages/async/src/synchro/counter.ts:48

Increments the counter by one.

number

The new value of the counter after incrementing.


reset(): void

Defined in: packages/async/src/synchro/counter.ts:38

Resets the counter to zero.

void


wait(targetValue, signal?): Promise<void>

Defined in: packages/async/src/synchro/counter.ts:69

Waits until the counter reaches the specified target value.

number

The value to wait for.

AbortSignal | null

An optional AbortSignal to cancel the wait.

Promise<void>