Need private packages and team management tools?Check out npm Teams »

thread-it

1.1.3 • Public • Published

Thread It License NPM version Dependency Status Build Status Coverage Status

Drastically simplified worker threads, on node v8 or v10 without --experimental-worker just wraps your code with a promise so you don't have to warry about a thing, just use thread it and it will use workers where can.

Choose any sync module from npm and instead of require use threadIt.

Caution: not all data types can be passed to Worker Thread, for example you just can't pass a function, read carefully what types are supported.

Install

npm i thread-it

API

threadIt(name[, options])

Under the hood threadId uses holdUp so you can use the same options to find a free worker from queue.

  • name - string
  • options - options may contain:
    • log
    • count
    • time

Also you can set THREAD_IT_COUNT env variable to workers count, if 0 it means disabled worker threads.

const threadIt = require('thread-it');
 
// init workers, depend on os.cpus()
threadIt.init();
 
const putout = threadIt('putout');
const result = await putout(`const t = 'hello'`);
 
// when you need to override options use
threadIt('putout', {
    count: 5,       // default
    time: 1000,     // default
    log: () => {},  // default
});
 
// terminate workers when no need anymore
threadIt.terminate();

Related

  • hold-up - setInterval with promises, counter and error handling
  • currify - translate the evaluation of a function that takes multiple arguments into evaluating a sequence of functions, each with a single or more arguments.
  • fullstore - functional variables.
  • wraptile - translate the evaluation of a function that takes multiple arguments into evaluating a sequence of 2 functions, each with a any count of arguments.

License

MIT

Install

npm i thread-it

DownloadsWeekly Downloads

296

Version

1.1.3

License

MIT

Unpacked Size

9.31 kB

Total Files

6

Last publish

Collaborators

  • avatar