thread-it
wrap any sync module to thread worker
Last updated a year ago by coderaiser .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install thread-it 
SYNC missed versions from official npm registry.

Thread It License NPM version 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

Current Tags

  • 3.0.0                                ...           latest (a year ago)

10 Versions

  • 3.0.0                                ...           a year ago
  • 2.0.0                                ...           4 years ago
  • 1.1.3                                ...           6 years ago
  • 1.1.2                                ...           7 years ago
  • 1.1.1                                ...           7 years ago
  • 1.1.0                                ...           7 years ago
  • 1.0.3                                ...           7 years ago
  • 1.0.2                                ...           7 years ago
  • 1.0.1                                ...           7 years ago
  • 1.0.0                                ...           7 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dependencies (3)
Dev Dependencies (11)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |