# hyber

> make node.js get power of multi-process.

Latest version **0.2.0** (published 2019-10-30) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; no vulnerabilities; high quality score.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2019-10-30 |
| First published | 2019-10-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Idan Loo |
| Maintainers | idan-loo |
| Keywords | multithread, node, async |

## Links

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

## Dependencies (1)

- [fs-extra](https://npm.io/package/fs-extra.md) ^8.1.0

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 0.2.0 (latest) — 2019-10-30
- 0.1.0 — 2019-10-30

## README

# hyber [![CircleCI](https://circleci.com/gh/IdanLoo/hyber.svg?style=svg)](https://circleci.com/gh/IdanLoo/hyber)

make node.js get power of multi-process.

## Experimental

Be cautious if you want to use it in your real projects.

## Introduction

As we all know, JavaScript, running in a single main process environment, can deal some specific jobs with another process. Unfortunately we can not create any child process directly.

Thank to the `child_process` module provided by `Node.js`, we are able to create child processes by shell commands. The most special one, `child_process.fork`, can be used to create child processes by JavaScript files.

The trouble is we have to leave the function of the child process an individual file and use the `message` mechanism to receive values from the child process. That's not really cool.

Image what if we create a child process as easy as creating a `Promise` object, how fantastic it will be.

## Principle

The `hyber` function will add some details, tranform your function into temporary file and call it.

Suppose you give a function like this

```javascript
function add(a, b) {
  return a + b
}
```

Then it will be transformed to

```
`(function add(a, b) {
    return a + b
})(arg1, arg2)
`
```

Once you give the arguments, they will be filled into the string like

```
;`(function add(a, b) {
    return a + b
})(10, 20)
`
```

Send message to the main process

```
`const value = (function add(a, b) {
    return a + b)
})(10, 20)
process.send(value)
`
```

Eventually, fork the file and handle the message by Promise.

That's it.

## Usage

### Import

```javascript
import hyber from 'hyber'
```

#### Install at first

```bash
npm install hyber
# or
yarn add hyber
```

### Without Argument

```javascript
const func = () => 10
const asyncFunc = hyber(func)

// 10
const result = await asyncFunc()
```

### With Arguments

`hyber` generates a new function, you should pass the arguments into the new one.

```javascript
const func = a => a + 10
const asyncFunc = hyber(func)

// 30
const result = await asyncFunc(20)
```

## NOTICE

Since the new function generated by `hyber`runs in a completely different process, it can not capture any variables in the current process. You have to pass all variables as arguments.

Use it only if you want to do tons of calculations without blocking the main process.

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