mgr

阅读时长 5 分钟读完

For easily managing slave processes.

mgr

Easier multithreading for Node.

Why?

Because multi-threaded node applications are unwieldy to work with, and I needed to work with them.

API

.job

Used by new child processes to expose functions (tasks) to parent processes.

It takes two arguments:

  • The name of the job (case sensitive).
  • A function to call when it's ready.

Jobs will only run when called by their parent process, and must always return a promise. If you've got a sweet Babel setup, I recommend using async functions. They're way nicer and crafted from unicorn tears.

When a job finishes, the value is sent to the parent process (same goes for errors).

.Fork

Fork creates a new child node process and aims it at a file path you pass it. Any jobs declared by the child process can be run through Fork.

Paths must be absolute.

fork.run

Starts a job in the child process, returning a promise.

Job names are case-sensitive.

If the job is expecting arguments, you can pass one immediately after the job name.

To keep stuff simple, only one argument is allowed.

Installing

From npm

From GitHub

Running tests

First, install from GitHub. npm only has the compiled code.

Be sure to run the build first:

Now you can run the tests.


<dl> <dt>mgr</dt> <dd>Abbreviation, "manager"</dd> </dl>

HomePage

https://github.com/PsychoLlama/mgr#readme

Repository

git+https://github.com/PsychoLlama/mgr.git

来源:JavaScript中文网 ,转载请注明来源 https://www.javascriptcn.com/post/60066f451d8e776d08040f07

纠错
反馈