multithreading
Version:
The missing standard library for multithreading in JavaScript (Works in the browser, Node.js, Deno, Bun).
24 lines (23 loc) • 950 B
TypeScript
import { type MutexGuard } from "./mutex.js";
import { Serializable, toDeserialized, toSerialized } from "../shared.js";
import type { SharedMemoryView } from "../types.js";
export declare class Condvar extends Serializable {
#private;
constructor(_buffer?: SharedArrayBuffer);
blockingWait<T extends SharedMemoryView | void>(guard: MutexGuard<T>): void;
/**
* Asynchronously waits for a notification. Safe to use on the Main Thread.
* @param guard The MutexGuard protecting the shared state.
*/
wait<T extends SharedMemoryView | void>(guard: MutexGuard<T>): Promise<void>;
/**
* Wakes up one blocked thread waiting on this Condvar.
*/
notifyOne(): void;
/**
* Wakes up all blocked threads waiting on this Condvar.
*/
notifyAll(): void;
[toSerialized](): readonly [SharedArrayBuffer];
static [toDeserialized](obj: ReturnType<Condvar[typeof toSerialized]>[0]): Condvar;
}