# clusterun

> Run tasks in cluster mode.

Latest version **0.1.1** (published 2018-03-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install clusterun
pnpm add clusterun
yarn add clusterun
bun add clusterun
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2018-03-08 |
| First published | 2018-03-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | hengwu |
| Maintainers | hengwu |
| Keywords | cluster, parallel |

## Links

- npm: https://www.npmjs.com/package/clusterun
- Repository: https://github.com/shenfe/clusterun
- Homepage: https://github.com/shenfe/clusterun#readme
- Issues: https://github.com/shenfe/clusterun/issues
- npm.io page: https://npm.io/package/clusterun

## Recent versions

- 0.1.1 (latest) — 2018-03-08
- 0.1.0 — 2018-03-07

## README

# clusterun

> Run tasks in cluster mode easily.

## Installation

```bash
$ npm install clusterun --save
```

## Usage

### function `clusterun`

Master => Workers => Master

```js
const { clusterun, registerTask, dispatchTask } = require('clusterun');

const runner = function () {
    // run by Master, to create tasks and dispatch them to Workers
};

const handler = async function (taskName, taskData) {
    let result;
    // run by Workers, to process tasks and produce results
    return result;
};

const callback = function (taskName, taskSourceData, taskResultData) {
    // run by Master, to handle task results
};

clusterun(runner, handler, callback, {
    clusterNumber: 2, // number of clusters; optional; default: number of CPU
    autoRestart: true, // whether to restart a dead Worker automatically; optional; default: false
});
```

### function `registerTask`

Register a type of task, with a hash-of-task-data function. Called by Master.

```js
registerTask('my-computing-task', aHashCodeFunctionForTaskData);
```

### function `dispatchTask`

Dispatch a task to Worker. Called by Master.

```js
dispatchTask('my-computing-task', taskData);
```

### helper functions

name | function | usage
:---: | :--- | :---
whoami | check the role of the current process, and output logs if any | `role = whoami()` `whoami('computing task A')`
ifMaster | run if the current is Master | `ifMaster() && doSth()` `ifMaster(doSth)`
ifWorker | run if the current is Worker | `ifWorker() && doSth()` `ifWorker(doSth)`

## License

MIT

---
_Source: https://npm.io/package/clusterun · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
