npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

proxy-worker-controller

v0.9.0

Published

Simple class to extend your project with workers instances

Downloads

5

Readme

proxy-worker-controller

Simple and lightweight module to extend your node.js classes with multithreading functions

Installation

To install the most recent release from npm, run:

npm install talib-wasm --save

Examples

Simple usage

example nodejs class file:

const ProxyWorkerController = require('proxy-worker-controller');

class ExampleProxyClass extends ProxyWorkerController {
    constructor(a, b) {
        // Insert this code to your class to use multithreading with workers
        // THIS CODE IS MANDATORY {
        const pwcResult = super(a, b);
        if (pwcResult && !(pwcResult instanceof ExampleProxyClass)) {
            return pwcResult;
        }
        // } 


        this.__a = a;
        this.__b = b;
    }

    method1(a) {
        console.log('called', 'method1', a);
        return this.__a;
    }

    method2(b) {
        console.log('called', 'method2', b);
        return this.__b;
    }
}

module.exports = ExampleProxyClass;

run code snippet:

npm run example-01

Output:

  proxy-worker-controller:main-thread sending message bb6650b0-c902-4caf-b2bd-c59260ad277d constructor [ 111, 222 ] +0ms
  proxy-worker-controller:main-thread sending message 451b0ea4-de54-4cfc-ad90-02c6b3d0d29a method1 [ 'a' ] +3ms
2020-01-29T10:07:46.746Z proxy-worker-controller:worker WORKER STARTED
2020-01-29T10:07:46.748Z proxy-worker-controller:worker CALLED METHOD {"method":"init","payload":{"parentPort":{"_events":{},"_eventsCount":2},"mainClassFilename":"/Users/user/Documents/own-projects/proxy-worker-controller/examples/01-example-call/example-proxy-class.js"}}
  proxy-worker-controller:main-thread resolved message 451b0ea4-de54-4cfc-ad90-02c6b3d0d29a 111 null +41ms
method1 111
  proxy-worker-controller:main-thread sending message e4edae4f-d02f-4dab-b952-622e3b713d77 method2 [ 'b' ] +1ms
2020-01-29T10:07:46.749Z proxy-worker-controller:worker CALLED METHOD {"uuid":"bb6650b0-c902-4caf-b2bd-c59260ad277d","method":"send","payload":{"property":"constructor","payload":[111,222]}}
2020-01-29T10:07:46.749Z proxy-worker-controller:worker CALLED METHOD {"uuid":"451b0ea4-de54-4cfc-ad90-02c6b3d0d29a","method":"send","payload":{"property":"method1","payload":["a"]}}
  proxy-worker-controller:main-thread resolved message e4edae4f-d02f-4dab-b952-622e3b713d77 222 null +0ms
method2 222
called method1 a
2020-01-29T10:07:46.750Z proxy-worker-controller:worker CALLED METHOD {"uuid":"e4edae4f-d02f-4dab-b952-622e3b713d77","method":"send","payload":{"property":"method2","payload":["b"]}}
called method2 b

Methods

Worker instance makes all of class instance methods async. Use await to receive results.

terminate()

Terminates worker instance. Use it to prevent CPU and Memory leaks.