Class Wraker

The Wraker class provides an interface for interacting with a web worker. It allows sending requests to the worker and handling responses asynchronously.

// Create a new Wraker instance with a worker script URL
const instance = new Wraker(new URL("worker.js", import.meta.url), {
type: "module",
});
// Initialize a Wraker instance from an existing Worker
const worker = new Worker("worker.js");
const instance = Wraker.fromWorker(worker);
// Fetch data from the worker
const data = await instance.fetch("/hello");
console.log(data.body); // Hello, world!

Constructors

Methods

Constructors

  • Create a new Wraker instance

    Parameters

    • OptionalscriptURL: string | URL

      URL of the worker script

    • Optionaloptions: WorkerOptions

      Worker options

    Returns Wraker

    Wraker instance

    const instance = new Wraker(new URL("worker.js", import.meta.url), {
    type: "module",
    });

Methods

  • Initialize a Wraker instance from an existing Worker

    Parameters

    • worker: Worker

      Worker instance

    Returns Wraker

    Wraker instance

    const worker = new Worker("worker.js");
    const instance = Wraker.fromWorker(worker);