# immediate-invocation

> Small module that ease the invocation of a function within a setImmediate call

Latest version **1.0.0** (published 2015-09-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install immediate-invocation
pnpm add immediate-invocation
yarn add immediate-invocation
bun add immediate-invocation
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2015-09-04 |
| First published | 2015-09-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Hernán Tierno |
| Maintainers | hernanhht |

## Links

- npm: https://www.npmjs.com/package/immediate-invocation
- Repository: https://github.com/hernanhht/immediate-invocation
- Issues: https://github.com/hernanhht/immediate-invocation/issues
- npm.io page: https://npm.io/package/immediate-invocation

## Recent versions

- 1.0.0 (latest) — 2015-09-04

## README

## Immediate
Small module that ease the invocation of a function within a setImmediate call. Following the best practice of always calling callbacks in an async fashion, this library will add some syntactic sugar (a little implementation of a [Cristian Douce](https://github.com/cristiandouce) idea).

### Classic invocation of a callback

A typical node.js code looks like this:

```js
function addNumber(first, second, cb) {
  if (first === null) {
    return cb(new Error('first argument is mandatory'));
  }
  
  cb(null, first + second);
}
```

This has the drawback that breaks the implicit contract of executing the callback in the next tick.
To avoid this we can wrap the `cb` call with `setImmediate`:

### Invoking a callback with setImmediate

```js
function addNumber(first, second, cb) {
  if (first === null) {
    return setImmediate(function () {
      cb(new Error('first argument is mandatory'));
    });
  }

  return setImmediate(function () {
    cb(null, first + second);
  });
}
```

This is a bit verbose. Now an example using this module:

### Invoking a callback with this module (immediate)

```js
var immediate = require('immediate');

function addNumber(first, second, cb) {
  if (first === null) {
    return immediate(cb, new Error('first argument is mandatory'));
  }
  
  immediate(cb, null, first + second);
}
```

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