Debian Codegraph @

node/sync-message-port/dist/lib/atomic_counter.d.ts

raw
1 /**
2 * A counter that can be atomically incremented and decremented, and which
3 * callers can synchronously listen for it becoming non-zero.
4 *
5 * This can be "open" or "closed"; once it's closed, {@link wait} will no longer
6 * emit useful events.
7 */
8 export declare class AtomicCounter {
9 /**
10 * The underlying BigInt64Array.
11 *
12 * The first BigInt64 represents the current value of the counter. The second
13 * BigInt64 is used to track the closed state.
14 */
15 private readonly buffer;
16 constructor(buffer: SharedArrayBuffer);
17 /** Atomically decrement the current value by one. */
18 decrement(): void;
19 /** Atomically increment the current value by one. */
20 increment(): void;
21 /**
22 * Closes the counter.
23 *
24 * This will cause any outstanding calls to {@link wait} on any thread to
25 * return `true` immediately.
26 */
27 close(): void;
28 /**
29 * Waits until the current value is not zero or the counter is closed.
30 *
31 * Returns `true` when the counter is non-zero *or* when it's closed. Returns
32 * `false` if the counter remains zero for `timeout` milliseconds.
33 */
34 wait(timeout?: number): boolean;
35 }