Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

troika-worker-utils

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

troika-worker-utils

Utilities for executing code in Web Workers

  • 0.45.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
287K
increased by5.29%
Maintainers
1
Weekly downloads
 
Created

What is troika-worker-utils?

The troika-worker-utils package provides utilities for managing and communicating with web workers in JavaScript. It simplifies the process of offloading tasks to background threads, allowing for more efficient and responsive applications.

What are troika-worker-utils's main functionalities?

WorkerPool

The WorkerPool feature allows you to create a pool of web workers to handle multiple tasks concurrently. This can be particularly useful for tasks that are computationally intensive and can be parallelized.

const { WorkerPool } = require('troika-worker-utils');

const pool = new WorkerPool({
  maxWorkers: 4,
  workerScriptURL: 'path/to/worker/script.js'
});

pool.postMessage({ task: 'heavyComputation', data: { /* some data */ } })
  .then(result => {
    console.log('Result from worker:', result);
  });

createWorker

The createWorker feature allows you to create a web worker from a function. This is useful for defining worker behavior inline without needing a separate worker script file.

const { createWorker } = require('troika-worker-utils');

const worker = createWorker(function() {
  self.onmessage = function(e) {
    const result = e.data * 2; // Example computation
    self.postMessage(result);
  };
});

worker.postMessage(10);
worker.onmessage = function(e) {
  console.log('Result from worker:', e.data); // Should log 20
};

Other packages similar to troika-worker-utils

FAQs

Package last updated on 02 Jan 2022

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