API Reference/createServer
function

createServer

typescript

Create a worker threads server for worker-side communication.

This function uses parentPort from worker_threads to establish communication with the host process.

Parameters

NameTypeDescription
startupDataWorkerThreadsStartupDataStartup data from the host process
optionsServerOptionsServer options

Examples

typescript
import { WorkerThreadsDriver } from 'isolated-workers/drivers/worker-threads';

const startupData = WorkerThreadsDriver.getStartupData();
const server = createServer(startupData);

server.onMessage(async (message, respond) => {
  console.log('Received:', message);
  await respond({
    tx: message.tx,
    type: message.type,
    payload: { result: 'ok' },
  });
});

server.start();