https://github.com/sdgluck/furck
:fork_and_knife: A better child_process.fork
https://github.com/sdgluck/furck
Last synced: 9 months ago
JSON representation
:fork_and_knife: A better child_process.fork
- Host: GitHub
- URL: https://github.com/sdgluck/furck
- Owner: sdgluck
- License: mit
- Created: 2017-08-12T12:34:50.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-09-21T07:10:21.000Z (over 8 years ago)
- Last Synced: 2025-07-29T04:05:19.501Z (10 months ago)
- Language: JavaScript
- Homepage:
- Size: 51.8 KB
- Stars: 1
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
furck
What the fork?
Made with ❤ at @outlandish
A simple child_process.fork wrapper...
- promisified child process execution
- better error reporting
- identifies "cannot find module" errors in silent mode
- resolves to last message for "one-off" jobs
## Install
```sh
npm install --save furck
```
```sh
yarn add furck
```
## Import
```js
// ES2015
import fork from 'furck'
```
```sh
// 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 process
- `fork.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
```js
// 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](http://bit.ly/2aVzthz)!
## License
MIT © [Sam Gluck](github.com/sdgluck)