// Scale an HTTP server across worker threads using fd-fanout. // Requires Node v24+ and a POSIX system (Linux, macOS). // // Run: node examples/server-threads/main.ts // Test: curl http://localhost:3000 import { once } from 'node:events'; import { createServer } from 'node:net'; import { workers, assign } from '../../src/index.ts'; import { serverThreads } from '../../src/serve/index.ts'; import { runServer } from './server.ts'; const server = createServer(); { // Run server threads await using run = workers(4); using threads = serverThreads(run.workers, server); const fanout = threads.map(([w, args]) => assign(w, runServer(...args))); void run(fanout); // Lifecycle await once(server.listen(3000), 'listening'); console.log('Listening on http://localhost:3000 with 4 worker threads'); await once(process, 'SIGINT'); server.close(); }