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

piscina

Package Overview
Dependencies
Maintainers
3
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

piscina

A fast, efficient Node.js Worker Thread Pool implementation

  • 1.4.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created

What is piscina?

Piscina is a fast, efficient Node.js Worker Threads pool implementation. It allows you to offload tasks to worker threads, helping to manage CPU-intensive tasks in a Node.js environment without blocking the main thread. This can significantly improve the performance of your Node.js applications, especially for tasks that are computationally expensive or I/O bound.

What are piscina's main functionalities?

Executing a Task

This demonstrates how to create a Piscina pool and execute a task in a worker thread. The task is defined in a separate file ('worker.js'), and the main thread communicates with the worker asynchronously, awaiting the result.

const Piscina = require('piscina');
const path = require('path');

const piscina = new Piscina({
  filename: path.resolve(__dirname, 'worker.js')
});

(async () => {
  const result = await piscina.run({ a: 1, b: 2 });
  console.log(result); // Output from your worker task
})();

Dynamic Task Module

This example shows how to run a dynamic task directly passed as a function to Piscina, without the need for a separate module file. This can be useful for small, on-the-fly tasks.

const Piscina = require('piscina');
const piscina = new Piscina();

(async () => {
  const result = await piscina.runTask({
    task: () => 'Hello from the worker!'
  });
  console.log(result); // 'Hello from the worker!'
})();

Other packages similar to piscina

Keywords

FAQs

Package last updated on 12 May 2020

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