process-fork-queue
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

Process Fork Queue

Make limited amount of node process forks.

Get Start

npm i process-fork-queue
// make a queue that limit max concurrent nodejs child process as 10
queue = new ForkQueue(10);

for (let i = 0; i < 100; i++) {
  queue
    .fork("./path-to-worker.js", ["--some-args", i], { silent: true })
    .then((childprocess) => {
      childprocess.on("message", console.log);
    });
}

API

  • new ForkQueue(maxConcurrent?: number)

    Construct a process fork queue.

    • maxConcurrent: max concurrent child process at one time. Default to 10
  • queue.fork(modulePath: string, args?: ReadonlyArray<string>, options?: ForkOptions): Promise<ChildProcess>

    Make a fork request.

    Receive the same args as NodeJS child_process.fork. The different is the returns is a promised ChildProcess.

    If the queue is full, the returned promise is pending to wait existed processes to end.

Readme

Keywords

none

Package Sidebar

Install

npm i process-fork-queue

Weekly Downloads

4

Version

1.0.3

License

ISC

Unpacked Size

48 kB

Total Files

10

Last publish

Collaborators

  • qefeng