Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
port_agent
Advanced tools
A RPC-like facility for making inter-thread function calls.
Port Agent provides a simple and intuitive interface that makes inter-thread function calls easy. Please see the Usage or Examples for instructions on how to use Port Agent in your application.
Error
from the other thread back to the caller.Agent.register
) persist until deregistered (i.e., Agent.deregister
) .An instance of an Agent
facilitates bi-directional communication between threads. The Agent
can be used in order to register a function in one thread and call it from another thread. Calls may be made from the main thread to a worker thread, and conversely from a worker thread to the main thread.
Late binding registrants will be called with previously awaited invocations; thus preventing a race condition. This means that you may await a call to a function that has not yet been registered. Once the function is registered in the other thread it will be called and its return value or Error
will be marshalled back to the caller.
Please see the Examples for variations on the Agent
's usage.
Agent
instance.import { Agent } from 'port_agent';
Agent
by passing a parentPort
or a Worker
instance to the Agent
constructor:In the main thread,
const worker = new Worker(fileURLToPath(import.meta.url));
const agent = new Agent(worker);
or, in a worker thread,
const agent = new Agent(worker_threads.parentPort);
Agent
instance.Agent.register
method:agent.register('hello_world', (value: string): string => `Hello, ${value} world!`);
Agent.call
method:const greeting = await agent.call<string>('hello_world', 'happy');
console.log(greeting); // Hello, happy world!
Please see the Simple Example for a working implementation.
Please see the Comprehensive Example for a working implementation.
<threads.MessagePort>
or <threads.Worker>
The message port.name <string>
The name of the registered function.
...args <Array<unknown>>
Arguments to be passed to the registered function.
Returns: <Promise<T>>
Errors:
Error
, the Error
will be marshalled back from the other thread to this thread and the Promise
will reject with the Error
as its failure reason.Error
will be marshalled back from the other thread to this thread and the Promise
will reject with the unhandled exception as its failure reason.Error
will be marshalled back from the other thread to this thread and the Promise
will reject with the exit code as its failure reason.name <string>
The name of the registered function.
fn <(...args: Array<any>) => any>
The registered function.
Returns: <void>
name <string>
The name of the registered function.
Returns: <void>
The Port Agent package adheres to semantic versioning. Breaking changes to the public API will result in a turn of the major. Minor and patch changes will always be backward compatible.
Excerpted from Semantic Versioning 2.0.0:
Given a version number MAJOR.MINOR.PATCH, increment the:
- MAJOR version when you make incompatible API changes
- MINOR version when you add functionality in a backward compatible manner
- PATCH version when you make backward compatible bug fixes
Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.
Port Agent supports one to one communication over a MessagePort
. BroadcastChannel
s are not presently supported.
Port Agent is strictly focused on efficient communication over MessagePort
s. Port Agent will not support communication over other communication channels e.g., Socket
s, IPC, etc.
[1.4.2] - 2025-01-15
FAQs
A RPC-like facility for making inter-thread function calls.
We found that port_agent demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.