Transport API

RuntimeTransport interface, createWorkerTransport, and createInProcessTransport for worker communication.

Transport API

Use the transport API when configuring how the runtime client communicates with worker processes. The transport abstracts MessagePort-based RPC over the worker boundary.

Types

Prop

Type

createWorkerTransport

createWorkerTransport(workerUrl) creates a RuntimeTransport that spawns a Web Worker from the given URL and establishes a MessageChannel for bidirectional communication. Returns RuntimeTransport & { worker: Worker }.

createInProcessTransport

createInProcessTransport() creates a RuntimeTransport that runs the kernel in the same process using a MessageChannel. No Web Worker is spawned. Use this for testing or Node.js environments where worker isolation is not needed.

Usage

Web Worker Transport (Default)

import { createRuntimeClient, fromMemoryFS } from '@taucad/runtime';
import { replicad } from '@taucad/runtime/kernels';
import { esbuild } from '@taucad/runtime/bundler';
import { createWorkerTransport } from '@taucad/runtime/transport';

const transport = createWorkerTransport(new URL('@taucad/runtime/worker', import.meta.url).href);

const client = createRuntimeClient({
  kernels: [replicad()],
  bundlers: [esbuild()],
  fileSystem: fromMemoryFS(),
  transport,
});

In-Process Transport (Testing)

import { createRuntimeClient, fromMemoryFS } from '@taucad/runtime';
import { replicad } from '@taucad/runtime/kernels';
import { esbuild } from '@taucad/runtime/bundler';
import { createInProcessTransport } from '@taucad/runtime/transport';

const client = createRuntimeClient({
  kernels: [replicad()],
  bundlers: [esbuild()],
  fileSystem: fromMemoryFS(),
  transport: createInProcessTransport(),
});

When to Use Each

TransportUse when
Default (none specified)Standard browser usage. Client auto-creates a worker.
createWorkerTransport(url)Custom worker URL or pre-built worker bundle.
createInProcessTransport()Testing, Node.js, or when worker isolation is not needed.