Security News
cURL Project and Go Security Teams Reject CVSS as Broken
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
@zlepper/rpc
Advanced tools
Allows RPC from the main thread to a background worker thread (Of any kind), using ES6 classes.
RPC is a tiny library that makes it easier to deal with web-workers, or any other kind of background thread in js/ts land.
npm install --save @zlepper/rpc
This sample shows how to implement a simple calculator that runs in a web-worker.
Start by creating the actual class that has the logic that should be run in your worker:
calculator.ts
:
export class Calculator {
public add(a: number, b: number): number {
return a + b;
}
public subtract(a: number, b: number): number {
return a - b;
}
}
Next create the worker initialization code:
worker.ts
import { startWorkerProvider, WebWorkerServerConnection } from '@zlepper/rpc';
import { Calculator } from './calculator';
const connection = new WebWorkerServerConnection();
startWorkerProvider(new Calculator(), connection);
Lastly in your main thread: Start the worker and connect to it:
main.ts
import { Calculator } from './calculator';
import { wrapBackgroundService, WebWorkerClientConnection } from '@zlepper/rpc';
const worker = new Worker('worker.ts', {
type: 'module'
});
const connection = new WebWorkerClientConnection(worker);
const wrapper = wrapBackgroundService<Calculator>(connection);
console.log(await wrapper.add(1, 2)); // Logs '3'
console.log(await wrapper.subtract(2, 1)); // Logs '1'
A couple of things to notice:
Promise
) will be wrapped
in promises in the main code, since the entire process is async.number
and expect to get number
back, that is what will happen.Questions you are probably asking yourself right now.
Return a Promise
, and we will automatically wait for it to resolve, and then return the actual
resolved value. If your Promise rejects, or the method throws an error, we pass that back to the client
and reject the promise there.
The library supports other ways of using "workers" than just web workers. e.g., worker_threads
from node.js.
Additionally, it is possible to plug your own connection implementation, fx to allow usage of WebSockets to communicate
with a web server.
Just .terminate()
the worker, or equivalent with whatever connection library you are using.
On the "client-side" we are using a Proxy
to intercept all getters, and then replacing the result
with a custom function. This function then passes a message through the connection
.
On the worker side we simply receive the events send from the client, and invokes the underlying
functions on the actual object provided to startWorkerProvider
.
This just sounds too good to be true? Yes it is, there are certain limitations that has to be obeyed for everything to keep working.
Proxy
this library does not work with IE11, but requires
a modern browser.FAQs
Allows RPC from the main thread to a background worker thread (Of any kind), using ES6 classes.
The npm package @zlepper/rpc receives a total of 1,491 weekly downloads. As such, @zlepper/rpc popularity was classified as popular.
We found that @zlepper/rpc demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.