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

@loaders.gl/worker-utils

Package Overview
Dependencies
Maintainers
9
Versions
205
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@loaders.gl/worker-utils

Utilities for running tasks on worker threads

  • 4.1.0-alpha.7
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
249K
increased by0.39%
Maintainers
9
Weekly downloads
 
Created

What is @loaders.gl/worker-utils?

@loaders.gl/worker-utils is a utility library designed to facilitate the use of web workers in JavaScript applications. It provides tools for creating, managing, and communicating with web workers, making it easier to offload heavy computations or tasks to background threads, thus improving the performance and responsiveness of web applications.

What are @loaders.gl/worker-utils's main functionalities?

Worker Pool

The Worker Pool feature allows you to manage a pool of web workers to handle multiple tasks concurrently. This is useful for parallel processing and can significantly improve performance for CPU-intensive tasks.

const { WorkerPool } = require('@loaders.gl/worker-utils');

const workerPool = new WorkerPool({
  source: 'path/to/worker.js',
  maxConcurrency: 4
});

async function runTask(data) {
  const result = await workerPool.process(data);
  console.log(result);
}

runTask({ some: 'data' });

Worker Farm

The Worker Farm feature provides a more flexible way to manage multiple workers, allowing you to dynamically allocate workers to different tasks as needed. This is useful for complex applications where tasks may vary in nature and resource requirements.

const { WorkerFarm } = require('@loaders.gl/worker-utils');

const workerFarm = new WorkerFarm({
  maxConcurrency: 4
});

async function runTask(data) {
  const worker = workerFarm.getWorker('path/to/worker.js');
  const result = await worker.process(data);
  console.log(result);
}

runTask({ some: 'data' });

Worker Pool with Task Queue

This feature demonstrates how to use a worker pool with a task queue, allowing you to process multiple tasks concurrently and collect their results. This is useful for batch processing scenarios.

const { WorkerPool } = require('@loaders.gl/worker-utils');

const workerPool = new WorkerPool({
  source: 'path/to/worker.js',
  maxConcurrency: 4
});

const tasks = [
  { some: 'data1' },
  { some: 'data2' },
  { some: 'data3' }
];

async function runTasks() {
  const results = await Promise.all(tasks.map(task => workerPool.process(task)));
  console.log(results);
}

runTasks();

Other packages similar to @loaders.gl/worker-utils

Keywords

FAQs

Package last updated on 10 Jan 2024

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