node package manager

sidewalk

Sidewalk

Sidewalk allows you to require a module into a separated process, and interact with it seamlessly. Multi-processing has never been this easy!

Install

$ npm install sidewalk
const sidewalk = require("sidewalk");

Usage

Heres a side by side comparison of require and sidewalk:

  1. Suppose you have a module calc.js

    // calc.js 
    exports.add = function(x, y, callback) {
        callback(null, x + y);
    }
  2. Use require to load it into the current process

    const calc = require("./calc.js");
     
    calc.add(1, 2, function(err, result) {
        console.log(result);
    });
  3. Or use sidewalk to load it into a separated process

    const calc = sidewalk("./calc.js").expose(["add"]);
     
    calc.add(1, 2, function(err, result) {
        console.log(result);
    });

Limitations

  • Sidewalk uses the built-in JSON based IPC, so it can NOT pass functions, regexes, errors, etc.

  • Remember to expose the method names first, or use the exec(func, arg1, arg2, ..., [callback]) API instead.

    Theres no wildcard getters without using the --harmony flag, we might switch to a ES6 Proxy implementation later, and forget about the expose!

License

WTFPL

            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
                    Version 2, December 2004
 
 Copyright (c) 2016 Yichao 'Peak' Ji
 
 Everyone is permitted to copy and distribute verbatim or modified
 copies of this license document, and changing it is allowed as long
 as the name is changed.
 
            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
 
  0. You just DO WHAT THE FUCK YOU WANT TO.