Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@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.
v3.3.0-alpha.14
FAQs
Utilities for running tasks on worker threads
The npm package @loaders.gl/worker-utils receives a total of 150,927 weekly downloads. As such, @loaders.gl/worker-utils popularity was classified as popular.
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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.