@wfh/thread-promise-pool
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

2 Node.js utilities: a thread worker pool and a promise queue

Thread worker pool

Create a thread pool, set maximum number of parallel threads to os.cpus().length - 1, maximum idle duration to be 1 minute.

import os from 'os';

const pool = new Pool(os.cpus().length - 1, 6000, {
  initializer: {file: 'source-map-support/register'},
  cwd: 'dist'
});

// Add 1 task to thread pool
const donePromise = pool.submit({
  file: 'worker-file.js',
  exportFn: 'default',
  args: []
});

Author your worker-file.js file

export default function(): Promise<Date> {
  return new Promise(resolve => setTimeout(() => resolve(new Date()), 1000));
}

Promise queue

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i @wfh/thread-promise-pool

      Weekly Downloads

      3

      Version

      1.0.2

      License

      MIT

      Unpacked Size

      138 kB

      Total Files

      32

      Last publish

      Collaborators

      • liujingbreak