Socket
Socket
Sign inDemoInstall

tiny-worker

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tiny-worker

Tiny WebWorker for Server


Version published
Weekly downloads
119K
decreased by-15.01%
Maintainers
1
Weekly downloads
 
Created

What is tiny-worker?

The tiny-worker npm package is a lightweight implementation of Web Workers for Node.js. It allows you to run JavaScript code in parallel threads, which can help improve the performance of CPU-intensive operations by offloading them to separate worker threads.

What are tiny-worker's main functionalities?

Creating a Worker

This feature allows you to create a new worker thread. The worker can execute code independently of the main thread and communicate back using messages.

const Worker = require('tiny-worker');
const worker = new Worker(function() {
  postMessage('Hello from the worker!');
});
worker.onmessage = function(event) {
  console.log(event.data); // 'Hello from the worker!'
};

Sending Messages to Worker

This feature allows the main thread to send messages to the worker thread. The worker can then process the message and send a response back to the main thread.

const Worker = require('tiny-worker');
const worker = new Worker(function() {
  onmessage = function(event) {
    postMessage('Received: ' + event.data);
  };
});
worker.onmessage = function(event) {
  console.log(event.data); // 'Received: Hello'
};
worker.postMessage('Hello');

Handling Errors in Worker

This feature allows you to handle errors that occur within the worker thread. You can set an error handler to catch and process any errors that are thrown in the worker.

const Worker = require('tiny-worker');
const worker = new Worker(function() {
  throw new Error('Something went wrong');
});
worker.onerror = function(error) {
  console.error('Worker error:', error.message); // 'Worker error: Something went wrong'
};

Other packages similar to tiny-worker

Keywords

FAQs

Package last updated on 20 Sep 2019

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc