Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/reggi/kinfunction

Run a function as a child process.
https://github.com/reggi/kinfunction

Last synced: about 1 month ago
JSON representation

Run a function as a child process.

Awesome Lists containing this project

README

        

# kinfunction

Allows you to run any function as a child process.

### Install

```
npm install kinfunction --save
```

### Usage

```
kinfunction(require, args, function, callback);
```

### Example

Here's an example of one function (`thefifthofnovember`) running twice and logging different a `process.pid` both times it runs. Because the child process doesn't have any access to the globals in this file we pass `"moment":"moment"` which will `require("moment")` to the variable `moment`. We also pass in the same arguments that the function takes.

[Here's a repo with this example in it.](https://github.com/reggi/play-kinfunction)

```
var moment = require("moment");
var kinfunction = require("kinfunction")

var thefifthofnovember = function(slogan, date) {
var day = moment(new Date(date)).format("dddd");
return slogan + " " + day + " " + process.pid;
}

var output = thefifthofnovember("remember remember", "Nov 5 2014");
console.log(output); // "remember remember Wednesday 5621"

kinfunction({
"moment": "moment"
}, {
"slogan": "remember remember",
"date": "Nov 5 2014",
}, thefifthofnovember, function(err, result) {
if (err) console.log(err);
console.log(result); // "remember remember Wednesday 5622"
});

```