furck
🍴 what the fork?
Made with ❤ at @outlandish
A simple child_process.fork wrapper:
- super simple API
- better error reporting
- promisified child process execution
- identifies "cannot find module" errors in silent mode
- execution resolves to last message for "one-off" jobs
Install
npm install --save furck
yarn add furck
Import
// ES2015
// CommonJSvar fork = require
Usage
furck(file, args, opts) : Object
Fork file
as a child process.
- file {String} (required) path to the file to execute
- args {Array} (optional) child_process args array
- opts {Object} (optional) child_process options object
Returns a "fork" (enhanced Promise) that...
- resolves with last message received (if the process exists cleanly)
- rejected when the process errors or exits with code > 0
(e.g. uncaught exceptions, unhandled rejections)
API
fork.send(data)
send data to the child processfork.on(event, fn)
hook into an event (e.g.message
)fork.kill([signal])
kill the process (signal default:SIGINT
) (returns a Promise)fork.process
underlying child process
Example
// master.jsconst fork = //=> squarepants // worker.jsprocess
Contributing
All pull requests and issues welcome!
If you're not sure how, check out the great video tutorials on egghead.io!
License
MIT © Sam Gluck