UNPKG

multithreading

Version:

The missing standard library for multithreading in JavaScript (Works in the browser, Node.js, Deno, Bun).

28 lines (27 loc) 1.06 kB
import type { SharedMemoryView } from "../types.js"; import { Serializable, toDeserialized, toSerialized } from "../shared.js"; export declare const INTERNAL_MUTEX_CONTROLLER: unique symbol; export interface MutexController { unlock(): void; blockingLock(): void; lock(): Promise<void>; } export declare class MutexGuard<T extends SharedMemoryView | void> implements Disposable { #private; constructor(data: T, mutex: MutexController); /** * Internal accessor for Condvar support */ get [INTERNAL_MUTEX_CONTROLLER](): MutexController; get value(): T; [Symbol.dispose](): void; dispose(): void; } export declare class Mutex<T extends SharedMemoryView | void = void> extends Serializable { #private; constructor(data?: T, _lockBuffer?: SharedArrayBuffer); blockingLock(): MutexGuard<T>; lock(): Promise<MutexGuard<T>>; [toSerialized](): readonly [readonly [SharedArrayBuffer, any], Transferable[]]; static [toDeserialized](obj: ReturnType<Mutex<any>[typeof toSerialized]>[0]): Mutex<any>; }