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 🙏

© 2025 – Pkg Stats / Ryan Hefner

workershare

v1.1.1

Published

Object sharing between multiple node worker threads and their parents.

Readme

workerShare

Object sharing between multiple node worker threads and their parents.

class WorkerShare

Class to create workers and share data with them.

constructor(data: Record<string | number, any>)

Creates a workerShare class with the data object. Note the data object must be serializable, so it cannot contain objects within the object.

WorkerShare.data

A proxy of the original data that automatically notifies workers of updates. Should be used when the parent alters the data.

WorkerShare.hire(url: string | URL, workerData)

Creates a new worker at the url listed, subscribing it to the parent's data. Returns the worker.

workerData.input?

Input to be passed into the worker as worker-threads.workerData.input. Note that the value cannot be an Object. If you want to send an object, convert it into JSON and parse the JSON in the worker.

workerData.onMessage(message: any)?

Function called whenever a message is received from the worker that is not data sync.

workerData.onError(error: Error)?

Function called when the worker errors.

workerData.onComplete(exitCode: number)?

Function called when the worker completes, after it is unsubscribed from the parent's data.

workerData.onOnline()?

Function called when the worker is online.

workerData.onMessageError(error: MessageError)?

Function called when the worker throws a message error.

WorkerShare.messageAll(message)

Posts a message to all workers.

WorkerShare.workers

The current amount of workers employed by the class.

WorkerShare.onAllComplete

A function that is executed when all workers have exited. The method takes in no arguments.

function receiveData(onMessageEvent): Record<string|number, any>

Function that should be called by the worker thread to process data. Returns the subscribed data.

onMessageEvent?: (message) => void param

Function called whenever a message is received from the parent that is not data sync.

Installation

npm i workerShare

Using the package

Import the class from workershare in your main thread, and import receiveData in your worker threads. When using the input data in a worker thread, note that it is located at workerData.input so that the initial value of the shared data can also be sent.

Note that only setting a property and deleting it will properly update the parent. Object.defineProperty and Object.setPropertyOf are not caught and transmitted to parent, and direct assignment to the object will unsubscribe the object.

Additionally, as both workerData and the shared data are themselves objects, workerData.input and properties of the shared data cannot be object, it will throw an error. As well, messages sent between the parent and the worker with a sender property set to workerShare will be caught and treated as a data sync message. Message events passed into the worker through the receiveData function's onMessageEvent and WorkerData.hire's onMessage will not receive the message.

The function WorkerShare.prototype.workers can be set with a function of type ()=>void. It will be ran when all workers have exited.

Contribution and License

Contributions are appreciated. Any bugs should be reported as GitHub issues.

If you are contributing or forking the software, note that the tests are not written as unit tests. To properly run the tests, change debug in the main file to true.

This code is licensed under the MIT License.

Copyright © 2025 Last8

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.