This is a blocking RPC implementation for use by WebAssembly imports. It relies upon SharedArrayBuffer and the Atomics API for blocking and data transfer.
Inspired by the Promise-based comlink library.
expose(exposedName, exposedValue, endpoint)consume(exposedName, endpoint)
import { expose } from 'blocking-rpc'; const worker = new Worker('...'); const obj = { log(x: any) { console.log(x); } // ... }; expose('example-obj', obj, worker);import { consume } from 'blocking-rpc'; import { parentPort } from 'node:worker_threads'; const example = consume('example-obj', parentPort!) example.log('hello from the consuming thread!');