safe_children
)
safe-instances (previously called
A complete, functional, fast and simple Node.js threading module.
safe-instances
was developed by Oratio.io for Oratio.js's Module System.
It's based on children pools, allowing you to
NOTE: With release 2.0, sending file names when doing new Child()
is DEPRECATED. You must do new ChildFile()
, as explained in the quick-start tutorial.
Installation
npm install safe-instances
Getting Started
var Child = ;var pool = 3; //Creates pool with 3 processesvar child = 'process.handle("randomMessage", function(value, callback){ callback(value) }' pool 3 * 60;childstart;child //NOTE: You might pass a third callback argument, too.;
Need to send file locations instead of strings when creating new script? Do:
ChildFileusesCache = false; //Default: true. Caches scripts for being re-used.var child = __dirname + 'script.js' 3 * 60;...
Documentation
new Child(code, pool, timeout)
Returns new Child object with following properties:
- child.setPool(pool); Sets child's pool to pool.
- child.encoding - Default:
utf8
. - child.commandType - Default:
node
. - child.timeout - The timeout you set when creating a child - defaults to 1 minute. Only works before beginning the script.
- child.logs - Do
console.log
s from the child appear on your console? - child.contact(event, message) - Returns
Promise
. Should be handled withprocess.handle
in the child process.