# node-ipc-call

> Non-blocking cross-process method call based on IPC for Node.js

Latest version **0.0.5** (published 2019-09-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-ipc-call
pnpm add node-ipc-call
yarn add node-ipc-call
bun add node-ipc-call
```

## 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.0.5 |
| Published | 2019-09-07 |
| First published | 2018-11-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | 8 |
| Dependencies | 0 |
| Unpacked size | 18.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Micooz |
| Maintainers | micooz |

## Links

- npm: https://www.npmjs.com/package/node-ipc-call
- Repository: https://github.com/micooz/node-ipc-call
- Homepage: https://github.com/micooz/node-ipc-call#readme
- Issues: https://github.com/micooz/node-ipc-call/issues
- npm.io page: https://npm.io/package/node-ipc-call

## Recent versions

- 0.0.5 (latest) — 2019-09-07
- 0.0.4 — 2019-07-07
- 0.0.3 — 2018-11-24
- 0.0.2 — 2018-11-24
- 0.0.1 — 2018-11-18

## README

# node-ipc-call

[![version](https://img.shields.io/npm/v/node-ipc-call.svg)](https://www.npmjs.com/package/node-ipc-call)
[![downloads](https://img.shields.io/npm/dt/node-ipc-call.svg)](https://www.npmjs.com/package/node-ipc-call)
[![license](https://img.shields.io/npm/l/node-ipc-call.svg)](https://github.com/micooz/node-ipc-call/blob/master/LICENSE)
[![Travis](https://img.shields.io/travis/micooz/node-ipc-call.svg)](https://travis-ci.org/micooz/node-ipc-call)
[![Coverage](https://img.shields.io/codecov/c/github/micooz/node-ipc-call/master.svg)](https://codecov.io/gh/micooz/node-ipc-call)

Non-blocking cross-process method call based on IPC for Node.js.

```
$ npm install --save node-ipc-call
```

## Usage

```js
const { Caller } = require('node-ipc-call');

const invoker = Caller.fork('./foo.js');

await invoker.invoke('sleep', 1000);
await invoker.invoke('max', [1, 2, 3]); // 3

invoker.destroy();
```

```js
// ./foo.js
const { Callee } = require('node-ipc-call');

const callee = new Callee();

// async method
callee.register(async function sleep(ms) {
  return new Promise((resolve) => {
    setTimeout(resolve, ms);
  });
});

// sync method
callee.register(function max(...args) {
  return Math.max(...args);
});

callee.listen();
```

## API

## Class: Caller

Added in: v0.0.1

### Caller.fork(modulePath, args, options)

Added in: v0.0.1

* `Caller.fork()` take the same parameters of [child_process.fork()](https://nodejs.org/dist/latest-v11.x/docs/api/child_process.html#child_process_child_process_fork_modulepath_args_options).

Returns **<Invoker>**.

## Class: Invoker

Added in: v0.0.1

Returned by `Caller.fork()`, you should make remote function calls via `Invoker`.

### invoker.invoke(name, args[, options])

Added in: v0.0.1

- `name` {String} The remote function name.
- `args` {Array} Arguments passed to the remote function.
- `options` {Object}
  - `timeout` {Number} In milliseconds. Default: 3000.

Returns `<Promise>`.

### invoker.destroy()

Added in: v0.0.1

Closes the IPC channel to child process, and rejects all pending calls. 

## Class: Callee

Added in: v0.0.1

### callee.register(arg)

Added in: v0.0.1

* `arg` {Function|Object|Array} The functions or an array of functions exposed to remote call.

Each function to be registered should **have an unique name**, register the same function multiple times is ok.

```js
callee.register(function foo() {});
callee.register({ foo() {} });
callee.register([ foo, bar ]);
callee.register(() => {}); // Error
```

### callee.listen()

Added in: v0.0.1

Starts to listen for method calls from parent process.

### callee.destroy()

Added in: v0.0.1

Stops listening method calls from parent process.

## License

MIT

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