Skip to content

fundamentool


rpc/node ​

Classes ​

NodeRpcClientWorker ​

Defined in: src/rpc/node/NodeRpcWorker/NodeRpcClientWorker.ts:27

RpcClient backed by a Node.js worker_threads Worker.

Example ​

ts
const client = new NodeRpcClientWorker('./worker.js', { workerData: { id: 1 } });
const result = await client.call('compute', [data]);

Extends ​

Constructors ​

Constructor ​
ts
new NodeRpcClientWorker(url, options?): NodeRpcClientWorker;

Defined in: src/rpc/node/NodeRpcWorker/NodeRpcClientWorker.ts:28

Parameters ​
ParameterType
urlstring
options?TNodeRpcClientWorkerOptions
Returns ​

NodeRpcClientWorker

Overrides ​

RpcClient.constructor

Properties ​

PropertyModifierTypeInherited fromDefined in
DEFAULT_EVENTSstaticstring[]RpcClient.DEFAULT_EVENTSsrc/rpc/RpcClient.ts:33

Methods ​

call() ​
ts
call<R>(
   method, 
   args?, 
options?): Promise<R>;

Defined in: src/rpc/RpcClient.ts:68

Calls a remote method and returns a Promise of its result.

Type Parameters ​
Type ParameterDefault type
Rany
Parameters ​
ParameterTypeDescription
methodstringMethod name exported by RpcConnect.
args?any[]Arguments to pass to the method.
options?TRpcClientRequestOptionsOptional timeout / abort signal / event names.
Returns ​

Promise<R>

Inherited from ​

RpcClient.call

clear() ​
ts
clear(): void;

Defined in: src/EventEmitter/index.ts:53

Removes all listeners without destroying the emitter.

Returns ​

void

Inherited from ​

RpcClient.clear

destroy() ​
ts
destroy(): void;

Defined in: src/rpc/RpcClient.ts:63

Destroys the client and releases resources.

Returns ​

void

Inherited from ​

RpcClient.destroy

emit() ​
ts
protected emit(data): void;

Defined in: src/EventEmitter/index.ts:27

Parameters ​
ParameterType
dataany
Returns ​

void

Inherited from ​

RpcClient.emit

on() ​
ts
on(
   event, 
   args?, 
   options?): TRpcUnsubscribe;

Defined in: src/rpc/RpcClient.ts:72

Subscribes to a server-side event stream.

Parameters ​
ParameterTypeDescription
eventstringEvent name.
args?any[]Arguments forwarded to the server subscription handler.
options?TRpcClientRequestOptions-
Returns ​

TRpcUnsubscribe

An unsubscribe function.

Inherited from ​

RpcClient.on

once() ​
ts
once(...listeners): () => void;

Defined in: src/EventEmitter/index.ts:46

Parameters ​
ParameterType
...listenersIEventEmitterListener<any>[]
Returns ​

() => void

Inherited from ​

RpcClient.once

proxy() ​
ts
proxy(): Promise<any>;

Defined in: src/rpc/RpcClient.ts:83

Returns a proxy object where every property is an async method call.

Returns ​

Promise<any>

Inherited from ​

RpcClient.proxy

subscribe() ​
ts
subscribe(...listeners): () => void;

Defined in: src/EventEmitter/index.ts:42

Registers one or more listeners; returns a function that removes them all.

Parameters ​
ParameterType
...listenersIEventEmitterListener<any>[]
Returns ​

() => void

Inherited from ​

RpcClient.subscribe

taskCount() ​
ts
taskCount(): number;

Defined in: src/rpc/RpcClient.ts:59

Returns the number of currently pending calls.

Returns ​

number

Inherited from ​

RpcClient.taskCount


NodeRpcClientWorkerPool ​

Defined in: src/rpc/node/NodeRpcWorker/NodeRpcClientWorkerPool.ts:18

Pool of NodeRpcClientWorker instances that distributes calls to the least-busy worker.

Example ​

ts
const pool = new NodeRpcClientWorkerPool('./worker.js', { maxWorkers: 4 });
const result = await pool.call('compute', [data]);
pool.destroy();

Extends ​

Constructors ​

Constructor ​
ts
new NodeRpcClientWorkerPool(url, options?): NodeRpcClientWorkerPool;

Defined in: src/rpc/node/NodeRpcWorker/NodeRpcClientWorkerPool.ts:19

Parameters ​
ParameterType
urlstring
options?TNodeRpcClientWorkerPoolOptions
Returns ​

NodeRpcClientWorkerPool

Overrides ​

RpcClientPool.constructor

Methods ​

call() ​
ts
call<A, R>(...args): Promise<R>;

Defined in: src/rpc/RpcClientPool.ts:118

Routes the call to the least-busy worker.

Type Parameters ​
Type ParameterDefault type
A extends any[]any[]
Rany
Parameters ​
ParameterType
...args[string, A, TRpcClientRequestOptions]
Returns ​

Promise<R>

Inherited from ​

RpcClientPool.call

clear() ​
ts
clear(): void;

Defined in: src/EventEmitter/index.ts:53

Removes all listeners without destroying the emitter.

Returns ​

void

Inherited from ​

RpcClientPool.clear

destroy() ​
ts
destroy(): void;

Defined in: src/rpc/RpcClientPool.ts:110

Destroys all workers in the pool and the pool itself.

Returns ​

void

Inherited from ​

RpcClientPool.destroy

emit() ​
ts
protected emit(data): void;

Defined in: src/EventEmitter/index.ts:27

Parameters ​
ParameterType
dataany
Returns ​

void

Inherited from ​

RpcClientPool.emit

getWorker() ​
ts
getWorker(): IRpcClient;

Defined in: src/rpc/RpcClientPool.ts:64

Returns the least-busy worker, creating a new one if a slot is free. If all slots are busy, returns the worker with the fewest active tasks.

Returns ​

IRpcClient

The selected Client instance.

Inherited from ​

RpcClientPool.getWorker

getWorkers() ​
ts
getWorkers(count?): IRpcClient[];

Defined in: src/rpc/RpcClientPool.ts:40

Pre-creates exactly count workers (cycling through slots up to maxWorkers). Useful in tests to ensure workers exist before attaching servers.

Parameters ​
ParameterTypeDefault valueDescription
countnumber0Number of worker instances to pre-create.
Returns ​

IRpcClient[]

Array of the created/existing worker instances.

Inherited from ​

RpcClientPool.getWorkers

on() ​
ts
on(...args): TRpcUnsubscribe;

Defined in: src/rpc/RpcClientPool.ts:127

Routes the subscription to the least-busy worker.

Parameters ​
ParameterType
...args[string, any[], TRpcClientRequestOptions]
Returns ​

TRpcUnsubscribe

Inherited from ​

RpcClientPool.on

once() ​
ts
once(...listeners): () => void;

Defined in: src/EventEmitter/index.ts:46

Parameters ​
ParameterType
...listenersIEventEmitterListener<any>[]
Returns ​

() => void

Inherited from ​

RpcClientPool.once

proxy() ​
ts
proxy(): Promise<Record<string, any>>;

Defined in: src/rpc/RpcClientPool.ts:136

Returns a proxy from the least-busy worker.

Returns ​

Promise<Record<string, any>>

Inherited from ​

RpcClientPool.proxy

subscribe() ​
ts
subscribe(...listeners): () => void;

Defined in: src/EventEmitter/index.ts:42

Registers one or more listeners; returns a function that removes them all.

Parameters ​
ParameterType
...listenersIEventEmitterListener<any>[]
Returns ​

() => void

Inherited from ​

RpcClientPool.subscribe

taskCount() ​
ts
taskCount(): number;

Defined in: src/rpc/RpcClientPool.ts:141

Returns the total number of pending tasks across all workers.

Returns ​

number

Inherited from ​

RpcClientPool.taskCount


NodeRpcConnectWorker ​

Defined in: src/rpc/node/NodeRpcWorker/NodeRpcConnectWorker.ts:17

Server-side RPC handler that runs inside a Node.js worker_threads Worker. Call NodeRpcConnectWorker.run(exports) at the top of the worker script to wire up the server.

Example ​

ts
// inside worker.js
await NodeRpcConnectWorker.run({ greet: (name) => `Hello, ${name}!` });

Extends ​

Constructors ​

Constructor ​
ts
new NodeRpcConnectWorker(options): NodeRpcConnectWorker;

Defined in: src/rpc/RpcConnect.ts:45

Parameters ​
ParameterType
options| TRpcConnectOptions | TRpcConnectOptionsInit
Returns ​

NodeRpcConnectWorker

Inherited from ​

RpcConnect.constructor

Properties ​

PropertyModifierTypeDefault valueInherited fromDefined in
interruptstatic<A>(millis?, params?) => Promise<A>waitRpcConnect.interruptsrc/rpc/RpcConnect.ts:35

Methods ​

destroy() ​
ts
destroy(): void;

Defined in: src/rpc/RpcConnect.ts:57

Returns ​

void

Inherited from ​

RpcConnect.destroy

dispatch() ​
ts
dispatch(data): void;

Defined in: src/rpc/RpcConnect.ts:61

Parameters ​
ParameterType
dataany
Returns ​

void

Inherited from ​

RpcConnect.dispatch

dispatchEncoded() ​
ts
dispatchEncoded(encodedData): void;

Defined in: src/rpc/RpcConnect.ts:65

Parameters ​
ParameterType
encodedDataTRpcEncodedData
Returns ​

void

Inherited from ​

RpcConnect.dispatchEncoded

run() ​
ts
static run(exports): Promise<RpcConnect>;

Defined in: src/rpc/node/NodeRpcWorker/NodeRpcConnectWorker.ts:18

Parameters ​
ParameterType
exportsRecord<string, any>
Returns ​

Promise<RpcConnect>

Type Aliases ​

TNodeRpcClientWorkerOptions ​

ts
type TNodeRpcClientWorkerOptions = {
  onError?: (error) => void;
  workerData?: any;
};

Defined in: src/rpc/node/NodeRpcWorker/NodeRpcClientWorker.ts:13

Options for NodeRpcClientWorker.

Properties ​

onError? ​
ts
optional onError?: (error) => void;

Defined in: src/rpc/node/NodeRpcWorker/NodeRpcClientWorker.ts:17

Called when the worker emits an error event or exits with a non-zero code.

Parameters ​
ParameterType
errorany
Returns ​

void

workerData? ​
ts
optional workerData?: any;

Defined in: src/rpc/node/NodeRpcWorker/NodeRpcClientWorker.ts:15

Data passed to the worker via workerData (available as workerData in worker_threads).


TNodeRpcClientWorkerPoolOptions ​

ts
type TNodeRpcClientWorkerPoolOptions = TNodeRpcClientWorkerOptions & {
  maxWorkers?: number;
};

Defined in: src/rpc/node/NodeRpcWorker/NodeRpcClientWorkerPool.ts:5

Options for NodeRpcClientWorkerPool.

Type Declaration ​

NameTypeDescriptionDefined in
maxWorkers?numberMaximum number of worker threads to spawn (default: 1).src/rpc/node/NodeRpcWorker/NodeRpcClientWorkerPool.ts:7

MIT License