node:cluster
| Imports | Implementation |
|---|---|
node:cluster | @bytecodealliance/jco-std/wasi/0.2.x/node/24.x.x/cluster |
A guest has no process model, so node:cluster follows the same pattern as
node:child_process. When bundled source imports it, Jco ensures the selected world
declares the interface, editing the .wit file in place, installing the definition under
deps/jco-node-0.1.0, and printing a CLI warning naming the changed files:
world app {
import jco:node/cluster@0.1.0;
// component imports and exports...
}
Declaring or generating the import does not grant host access. Jco’s default
transpilation map uses a provider that throws ERR_JCO_CLUSTER_ADAPTER_REQUIRED, so an
application must make the security decision explicitly, for example by mapping the Node
host provider:
jco transpile component.wasm \
--map 'jco:node/cluster@0.1.0=@bytecodealliance/jco-std/wasi/0.2.x/node/24.x.x/cluster/host/node'
That produces the call path guest node:cluster → WIT capability → host adapter → Node
node:cluster. Because a transpiled component is itself a Node process, cluster.fork()
re-executes the entry, so a forked worker runs the component again and observes itself as
a worker.
Two differences from Node are unavoidable:
- Event timing. Node delivers cluster events on its event loop. A guest cannot be
called back across the host boundary, so events are queued by the host and emitted
when the guest next touches the module;
cluster.pump()drains them on demand. - Messages cross as JSON. WIT has no dynamic value type, so values JSON cannot
represent – functions, symbols, cycles,
BigInt– are rejected rather than silently altered.
These throw ERR_JCO_UNSUPPORTED_NODE_API rather than failing quietly:
| API | Why |
|---|---|
worker.process | A ChildProcess handle cannot cross the component boundary. |
listening event, handle sharing | Cluster distributes Node net handles; guest servers are wasi:sockets, so nothing hooks them. SCHED_RR is accepted but does not distribute guest connections. |
setupPrimary({ exec, execArgv, stdio, uid, gid, inspectPort, serialization }) | These configure the host runner executing the component, not a guest file. |
cluster.isMaster and cluster.setupMaster() are deprecated in Node, so they throw
ERR_JCO_UNSUPPORTED_DEPRECATED_NODE_API and point at isPrimary/setupPrimary.