node package manager


co wrapper for Nodes child_process modules fork method

Recieve asynchrous messages from forked processes using ES6 yield instead of using callback functions.

Built for and tested with co, but doesn't depend on it. It should also work with the likes of suspend, gen-run, etc.

npm install co-fork

Using co (npm i co)

process.send({hello: '...everybody :)'});
var fork = require('co-fork');
var co = require('co');
var child = fork('./child.js');
co(function *() {
  var msg = yield child('message');

Works with Node v0.11.x and v0.10.x (with a little extra effort)

node --harmony master.js

We can run our example code in v0.10.x using traceur

First install traceur

npm i traceur

Then create a file, master.transpile.js

var Traceur = require('traceur');
Traceur.require.makeDefault(function(filename) {  
  return !(/node_modules\/traceur/.test(filename));

This causes any required modules to be transpiled from es6 to es5 (except traceur itself). We then require the master.js file to transpile it (and it's dependencies), and then execute it.

Now we can run our code in v0.10.x with

node master.transpile.js
npm test

This will work seamlessly whether node version is above or below v0.11.x


  • Removing an event listener, without access to the callback. hmm.