Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@loaders.gl/worker-utils
Advanced tools
@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.
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();
workerpool is a library that provides a simple way to create a pool of web workers to run tasks in parallel. It offers similar functionality to @loaders.gl/worker-utils, including task queuing and worker management. However, workerpool is more focused on simplicity and ease of use, while @loaders.gl/worker-utils provides more advanced features and flexibility.
threads is a library for creating and managing web workers with a focus on simplicity and type safety. It provides a high-level API for running tasks in parallel and supports TypeScript out of the box. Compared to @loaders.gl/worker-utils, threads offers a more modern and type-safe approach, but may lack some of the advanced features and flexibility provided by @loaders.gl/worker-utils.
comlink is a library that simplifies the use of web workers by providing a proxy-based API for communication between the main thread and workers. It allows you to call worker functions as if they were local functions, making it easier to work with web workers. While comlink focuses on ease of use and seamless communication, @loaders.gl/worker-utils provides more comprehensive tools for managing worker pools and farms.
This module contains shared utilities for loaders.gl, a collection of framework-independent 3D and geospatial loaders (parsers).
For documentation please visit the website.
FAQs
Utilities for running tasks on worker threads
We found that @loaders.gl/worker-utils demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 8 open source maintainers collaborating on the project.
Did you know?
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.