Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/reggi/kinfunction
- Owner: reggi
- Created: 2014-11-06T18:22:44.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2014-11-06T19:28:40.000Z (about 10 years ago)
- Last Synced: 2024-10-05T10:45:29.057Z (about 2 months ago)
- Language: JavaScript
- Size: 113 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
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"
});```