Appearance
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
| Parameter | Type |
|---|---|
url | string |
options? | TNodeRpcClientWorkerOptions |
Returns
Overrides
Properties
| Property | Modifier | Type | Inherited from | Defined in |
|---|---|---|---|---|
DEFAULT_EVENTS | static | string[] | RpcClient.DEFAULT_EVENTS | src/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 Parameter | Default type |
|---|---|
R | any |
Parameters
| Parameter | Type | Description |
|---|---|---|
method | string | Method name exported by RpcConnect. |
args? | any[] | Arguments to pass to the method. |
options? | TRpcClientRequestOptions | Optional timeout / abort signal / event names. |
Returns
Promise<R>
Inherited from
clear()
ts
clear(): void;Defined in: src/EventEmitter/index.ts:53
Removes all listeners without destroying the emitter.
Returns
void
Inherited from
destroy()
ts
destroy(): void;Defined in: src/rpc/RpcClient.ts:63
Destroys the client and releases resources.
Returns
void
Inherited from
emit()
ts
protected emit(data): void;Defined in: src/EventEmitter/index.ts:27
Parameters
| Parameter | Type |
|---|---|
data | any |
Returns
void
Inherited from
on()
ts
on(
event,
args?,
options?): TRpcUnsubscribe;Defined in: src/rpc/RpcClient.ts:72
Subscribes to a server-side event stream.
Parameters
| Parameter | Type | Description |
|---|---|---|
event | string | Event name. |
args? | any[] | Arguments forwarded to the server subscription handler. |
options? | TRpcClientRequestOptions | - |
Returns
An unsubscribe function.
Inherited from
once()
ts
once(...listeners): () => void;Defined in: src/EventEmitter/index.ts:46
Parameters
| Parameter | Type |
|---|---|
...listeners | IEventEmitterListener<any>[] |
Returns
() => void
Inherited from
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
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
| Parameter | Type |
|---|---|
...listeners | IEventEmitterListener<any>[] |
Returns
() => void
Inherited from
taskCount()
ts
taskCount(): number;Defined in: src/rpc/RpcClient.ts:59
Returns the number of currently pending calls.
Returns
number
Inherited from
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
| Parameter | Type |
|---|---|
url | string |
options? | TNodeRpcClientWorkerPoolOptions |
Returns
Overrides
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 Parameter | Default type |
|---|---|
A extends any[] | any[] |
R | any |
Parameters
| Parameter | Type |
|---|---|
...args | [string, A, TRpcClientRequestOptions] |
Returns
Promise<R>
Inherited from
clear()
ts
clear(): void;Defined in: src/EventEmitter/index.ts:53
Removes all listeners without destroying the emitter.
Returns
void
Inherited from
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
emit()
ts
protected emit(data): void;Defined in: src/EventEmitter/index.ts:27
Parameters
| Parameter | Type |
|---|---|
data | any |
Returns
void
Inherited from
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
The selected Client instance.
Inherited from
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
| Parameter | Type | Default value | Description |
|---|---|---|---|
count | number | 0 | Number of worker instances to pre-create. |
Returns
Array of the created/existing worker instances.
Inherited from
on()
ts
on(...args): TRpcUnsubscribe;Defined in: src/rpc/RpcClientPool.ts:127
Routes the subscription to the least-busy worker.
Parameters
| Parameter | Type |
|---|---|
...args | [string, any[], TRpcClientRequestOptions] |
Returns
Inherited from
once()
ts
once(...listeners): () => void;Defined in: src/EventEmitter/index.ts:46
Parameters
| Parameter | Type |
|---|---|
...listeners | IEventEmitterListener<any>[] |
Returns
() => void
Inherited from
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
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
| Parameter | Type |
|---|---|
...listeners | IEventEmitterListener<any>[] |
Returns
() => void
Inherited from
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
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
| Parameter | Type |
|---|---|
options | | TRpcConnectOptions | TRpcConnectOptionsInit |
Returns
Inherited from
Properties
| Property | Modifier | Type | Default value | Inherited from | Defined in |
|---|---|---|---|---|---|
interrupt | static | <A>(millis?, params?) => Promise<A> | wait | RpcConnect.interrupt | src/rpc/RpcConnect.ts:35 |
Methods
destroy()
ts
destroy(): void;Defined in: src/rpc/RpcConnect.ts:57
Returns
void
Inherited from
dispatch()
ts
dispatch(data): void;Defined in: src/rpc/RpcConnect.ts:61
Parameters
| Parameter | Type |
|---|---|
data | any |
Returns
void
Inherited from
dispatchEncoded()
ts
dispatchEncoded(encodedData): void;Defined in: src/rpc/RpcConnect.ts:65
Parameters
| Parameter | Type |
|---|---|
encodedData | TRpcEncodedData |
Returns
void
Inherited from
run()
ts
static run(exports): Promise<RpcConnect>;Defined in: src/rpc/node/NodeRpcWorker/NodeRpcConnectWorker.ts:18
Parameters
| Parameter | Type |
|---|---|
exports | Record<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
| Parameter | Type |
|---|---|
error | any |
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
| Name | Type | Description | Defined in |
|---|---|---|---|
maxWorkers? | number | Maximum number of worker threads to spawn (default: 1). | src/rpc/node/NodeRpcWorker/NodeRpcClientWorkerPool.ts:7 |