API reference

Every public class, method, and event in @codexo/exojs. Generated from source.

C

classInlineWorker

@codexo/exojs / core / stable

Runs a worker from a JavaScript source string instead of a separate script file, and owns the lifetime of the object URL that makes that possible. The intended source is the string emitted by the `?worker` import of `@codexo/exojs-build`, which inlines a TypeScript worker module and its imports as one classic script. Nothing about this class requires that build step, though: any self-contained classic-script source works. ```ts import workerSource from './generator.worker.ts?worker'; const worker = new InlineWorker(workerSource, { name: 'generator' }); worker.worker.onmessage = (event) => console.log(event.data); worker.postMessage(42); ``` There is no message protocol here: worker is the real `Worker`, so `onmessage`, `onerror`, `addEventListener` and structured clone behave exactly as they do without this class. postMessage is a convenience that additionally rejects use after destroy. The source runs as a **classic** script, so it cannot use `import`. Emitted `?worker` sources already satisfy this. A page whose Content-Security-Policy omits `blob:` from `worker-src` (or `child-src`/`default-src` as the fallback) blocks the construction; the error thrown by the constructor names that cause.

2
props
2
methods
0
events
Import
import { InlineWorker } from '@codexo/exojs'

Runs a worker from a JavaScript source string instead of a separate script file, and owns the lifetime of the object URL that makes that possible.

The intended source is the string emitted by the `?worker` import of `@codexo/exojs-build`, which inlines a TypeScript worker module and its imports as one classic script. Nothing about this class requires that build step, though: any self-contained classic-script source works.

```ts import workerSource from './generator.worker.ts?worker';

const worker = new InlineWorker(workerSource, { name: 'generator' });

worker.worker.onmessage = (event) => console.log(event.data); worker.postMessage(42); ```

There is no message protocol here: worker is the real `Worker`, so `onmessage`, `onerror`, `addEventListener` and structured clone behave exactly as they do without this class. postMessage is a convenience that additionally rejects use after destroy.

The source runs as a **classic** script, so it cannot use `import`. Emitted `?worker` sources already satisfy this.

A page whose Content-Security-Policy omits `blob:` from `worker-src` (or `child-src`/`default-src` as the fallback) blocks the construction; the error thrown by the constructor names that cause.

Constructors1
new(source: string, options: InlineWorkerOptionsOptions for InlineWorker.): InlineWorker
Methods2
destroy(): void
Terminate the worker immediately, discarding queued and in-flight work. Idempotent.
postMessage(message: unknown, transfer?: readonly Transferable[]): void
Post message to the worker, transferring ownership of everything in transfer.
Properties2
worker: Worker
The underlying worker. Attach listeners and transfer ownership of objects through this. Remains valid until destroy, which terminates it.
destroyed: boolean
Whether destroy has already run.
Source