UNPKG

multithreading

Version:

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

33 lines (32 loc) 1.36 kB
import type { SharedMemoryView } from "../types.js"; import { Serializable, toDeserialized, toSerialized } from "../shared.js"; export declare const INTERNAL_RWLOCK_CONTROLLER: unique symbol; export interface RwLockController { unlock(): void; } export declare class RwLockReadGuard<T extends SharedMemoryView | void> implements Disposable { #private; constructor(data: T, controller: RwLockController); get [INTERNAL_RWLOCK_CONTROLLER](): RwLockController; get value(): T; [Symbol.dispose](): void; dispose(): void; } export declare class RwLockWriteGuard<T extends SharedMemoryView | void> implements Disposable { #private; constructor(data: T, controller: RwLockController); get [INTERNAL_RWLOCK_CONTROLLER](): RwLockController; get value(): T; [Symbol.dispose](): void; dispose(): void; } export declare class RwLock<T extends SharedMemoryView | void = void> extends Serializable { #private; constructor(data?: T, _stateBuffer?: SharedArrayBuffer); blockingRead(): RwLockReadGuard<T>; read(): Promise<RwLockReadGuard<T>>; blockingWrite(): RwLockWriteGuard<T>; write(): Promise<RwLockWriteGuard<T>>; [toSerialized](): readonly [readonly [SharedArrayBuffer, any], Transferable[]]; static [toDeserialized](obj: ReturnType<RwLock<any>[typeof toSerialized]>[0]): RwLock<any>; }