
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
@zlepper/web-worker-rpc
Advanced tools
Provides a connection implementation for web-workers.
First install the library:
npm install --save @zlepper/rpc @zlepper/web-worker-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 } from '@zlepper/rpc';
import { WebWorkerServerConnection } from '@zlepper/web-worker-rpc';
import { Calculator } from './calculator';
// Create a wrapper around the connection. The specific wrapper class
// depends on which worker model you are using.
const connection = new WebWorkerServerConnection();
// Then provide the actual class you want to wrap.
startWorkerProvider(new Calculator(), connection);
Lastly in your main thread: Start the worker and connect to it:
// main.ts
import { Calculator } from './calculator';
import { wrapBackgroundService } from '@zlepper/rpc';
import { WebWorkerClientConnection } from '@zlepper/web-worker-rpc';
// First start the worker itself
const worker = new Worker('worker.ts', {
type: 'module'
});
// Wrap the connection, the class is again specific to the worker model
// you wish to use.
const connection = new WebWorkerClientConnection(worker);
// Lastly access the wrapped "instance" of your class.
const wrapper = wrapBackgroundService<Calculator>(connection);
console.log(await wrapper.add(1, 2)); // Logs '3'
console.log(await wrapper.subtract(2, 1)); // Logs '1'
Also check the full sample here.
FAQs
Unknown package
The npm package @zlepper/web-worker-rpc receives a total of 30 weekly downloads. As such, @zlepper/web-worker-rpc popularity was classified as not popular.
We found that @zlepper/web-worker-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
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.