multithreading
Version:
The missing standard library for multithreading in JavaScript (Works in the browser, Node.js, Deno, Bun).
23 lines (22 loc) • 1.02 kB
TypeScript
import type { JoinHandle } from "./types.js";
export * from "./sync/mod.js";
export { SharedJsonBuffer } from "./json_buffer.js";
export type { JoinHandle, Result, SharedMemoryView } from "./types.js";
export declare function initRuntime(config: {
maxWorkers: number;
}): void;
/**
* A branded type that ensures the array has been explicitly marked
* by the move() function.
*/
declare const moveTag: unique symbol;
export type MovedData<T extends any[]> = T & {
readonly [moveTag]: true;
};
export declare function move<Args extends any[]>(...args: Args): MovedData<Args>;
export declare function drop<T extends Disposable>(resource: T): void;
export declare function spawn<Args extends any[], R>(payload: MovedData<Args>, fn: (this: void, ...args: Args) => R | Promise<R>): JoinHandle<R>;
export declare function spawn<R>(fn: (this: void) => R | Promise<R>): JoinHandle<R>;
export declare function shutdown(): void;
export declare const isMainThread: boolean;
export declare const isWorkerThread: boolean;