New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

multithreading-toolkit

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

multithreading-toolkit

Node.js multithreading toolkit

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Multithreading toolkit

Install:

npm install multithreading-toolkit --save

workerThreadsFunction - Execution of a function in a separate thread (based on worker_threads module). Available for Node.js version 10.5.0 and higher.

workerThreadsFunction args:

  • source: Function or path to the module that exports the function (Function/String)
  • options: Options when creating a function (Object):
  • options.returnTimeout: Return timeout (milliseconds) (Default: 60000)
  • options.eval: true, if the function was passed as the source, false if the path to the module was passed as the source (Default: false)
  • options.execArgv: execArgv for Worker instance (Array) (Default: [])
  • options.pool: Do I need to use a pool of workers (Bool) (Default: false)
  • options.poolOptions: Pool options for generic-pool

Example:

'use strict';

const myReturnTimeout = 1000000;
const { workerThreadsFunction } = require('multithreading-toolkit');

const someFunction = workerThreadsFunction(function (arg1, arg2, arg3) {
    // arg1, arg2, arg3 - Some data for calculations
    // Some heavy calculations, which usually block the thread
    return 'Some result';
}, {
    eval: true
});

// Call the function, passing in an array of arguments
someFunction([1, 2, 3], {returnTimeout: myReturnTimeout}).then(console.log).catch(console.error);

forkFunction - Execution of a function in a separate thread (based on child_process.fork).

forkFunction args:

  • source: Function or path to the module that exports the function (Function/String)
  • options: Options when creating a function (Object):
  • options.returnTimeout: Return timeout (milliseconds) (Default: 60000)
  • options.eval: true, if the function was passed as the source, false if the path to the module was passed as the source (Default: false)
  • options.forkOptions: options for child_process.fork
  • options.pool: Do I need to use a pool of workers (Bool) (Default: false)
  • options.poolOptions: Pool options for generic-pool

Example:

'use strict';

const myReturnTimeout = 1000000;
const { forkFunction } = require('multithreading-toolkit');

const someFunction = forkFunction(function (arg1, arg2, arg3) {
    // arg1, arg2, arg3 - Some data for calculations
    // Some heavy calculations, which usually block the thread
    return 'Some result';
}, {
    eval: true
});

// Call the function, passing in an array of arguments
someFunction([1, 2, 3], {returnTimeout: myReturnTimeout}).then(console.log).catch(console.error);

Keywords

FAQs

Package last updated on 12 Feb 2019

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