Class Thread<Args, Output>

Creates a new thread using a specified script

Example

import { Thread } from 'nanothreads';

const handle = new Thread<[number, number], number>('./worker.js');
await handle.send(4, 1); // output: 5

Type Parameters

  • Args

  • Output

Hierarchy

Constructors

  • Type Parameters

    • Args

    • Output

    Parameters

    • src: string | URL
    • options: {
          id?: number;
          once: boolean;
      }
      • Optional id?: number
      • once: boolean

    Returns Thread<Args, Output>

Properties

channel: MessagePort
config?: {
    id?: number;
    once?: boolean;
}

Type declaration

  • Optional id?: number
  • Optional once?: boolean
handle: BrowserImpl<unknown>
options: IWorkerOptions & {
    eval?: boolean;
} = {}
src: string | WorkerThreadFn<Args, Output>
type: "inline" | "inline-blob" | "file"

Methods

  • Parameters

    • Rest ...data: Args extends any[] ? Args : [Args]

    Returns Promise<Output>

Generated using TypeDoc