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

@ms-cloudpack/worker-pool

Package Overview
Dependencies
Maintainers
3
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ms-cloudpack/worker-pool

General worker pool helper.

  • 0.1.1
  • npm
  • Socket score

Version published
Weekly downloads
207
decreased by-41.36%
Maintainers
3
Weekly downloads
 
Created
Source

@ms-cloudpack/worker-pool

Provides utilities for simplifying worker execution.

Usage

There are two source files when using workers - the worker entry, which hosts the code to be executed within the worker, and the host source, which instantiates the pool and executes the work.

Setting up a worker entry

First, let's set up the worker entry that will execute work inside the worker. Use initializeWorker to set up your api surface:

workerEntry.ts:

import { initializeWorker } from '@ms-cloudpack/worker-pool';
import { methodA, methodB } from './methods';

// Load any environmental side effects here.

// Then initialize the worker with the appropriate listeners and api dictionary.
initializeWorker({
  beforeEach: () => {...}, // optional
  afterEach: () => {...}, // optional
  methods: {
    methodA,
    methodB,
  },
});

Setting up the pool

In the host where we want to execute things to asynchronously run in the pool of workers:

import { WorkerPool } from '@ms-cloudpack/worker-pool';

const pool = new WorkerPool({ entry: './workerEntry.js' });

Executing work

Work is executed from the pool created above:

const result = await pool.execute('methodA', [arg1, arg2, etc]);

FAQs

Package last updated on 21 Feb 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