furck
v1.6.0
Published
what the fork? a simple child_process.fork wrapper
Downloads
14
Maintainers
Readme
furck
:fork_and_knife: 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
import fork from 'furck'
// CommonJS
var fork = require('furck')
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.js
const fork = require('furck')
fork('./worker')
.on('message', (m) => console.log(m)) //=> squarepants
.send('spongebob')
.then(() => console.log('all done'))
.catch((err) => console.log('uh-oh', err))
// worker.js
process.on('message', (m) => {
if (m === 'spongebob') {
process.send('squarepants')
process.exit(0)
}
})
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