1.6.0 • Published 8 years ago

furck v1.6.0

Weekly downloads
1
License
MIT
Repository
-
Last release
8 years ago

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 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

// 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

1.6.0

8 years ago

1.5.0

8 years ago

1.4.0

8 years ago

1.3.0

8 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago