1.2.2 • Published 9 years ago
fork-function v1.2.2
fork-function  
 
Fork a function to a child process.
Usage
Installation:
$ npm install fork-functionAPI:
forkFunction (function, callback)
Do stuff with the first function, this is passed to a newly created child process. The callback is called once the function is done (using the following pattern (err, result)), the first function is passed a function as its only argument, which when called (it accepts a single argument as the result value(s)) passes the value(s) back to the callback in the main process and ends the child process.
Example:
var forkFunction = require('fork-function')
forkFunction(function (done) {
  setTimeout(function () {
    // do some intense async work
    // ...
    // then call `done()` with some result
    done({hello: ['world']})
  }, 1500)
}, function (err, result) {
  if (err) console.error(err)
  console.log(result) // {hello: ['world']}
})