# call-next-tick

> Calls callbacks on next tick so you can avoid craziness from code that expects async to not execute immediately.

Latest version **2.0.1** (published 2017-03-11) · ISC license · 0 weekly downloads

## Install

```sh
npm install call-next-tick
pnpm add call-next-tick
yarn add call-next-tick
bun add call-next-tick
```

## 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 | 2.0.1 |
| Published | 2017-03-11 |
| First published | 2015-05-10 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jim Kang |
| Maintainers | jimkang |
| Keywords | async, sync, callback, nexttick |

## Links

- npm: https://www.npmjs.com/package/call-next-tick
- Repository: https://github.com/jimkang/call-next-tick
- Issues: https://github.com/jimkang/call-next-tick/issues
- npm.io page: https://npm.io/package/call-next-tick

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 2.0.1 (latest) — 2017-03-11
- 2.0.0 — 2017-03-11
- 1.1.2 — 2015-05-10
- 1.1.1 — 2015-05-10

## README

call-next-tick
==============

(Formerly conform-async.)

A handy wrapper for `process.nextTick` that you can use to call a callback on the next tick instead of immediate, even though you have the results for callback. [Here's why you'd want to do this](http://nodejs.org/api/process.html#process_process_nexttick_callback) (scroll to "It is very important...").

Installation
------------

    npm install call-next-tick

Usage
-----
    var callNextTick = require('call-next-tick');

    // callback expects to be called async.
    function getResultForSpecialSituation(id, callback) {
    	var error = null;
    	var constantResult = 'This is always the result';
		callNextTick(callback, error, constantResult);
    }

Instead of:

	// callback expects to be called async.
    function getResultForSpecialSituation(id, callback) {
    	var error = null;
    	var constantResult = 'This is always the result';
    	process.nextTick(function doTheCallWithTheParamsFromTheClosure() {
    		callback(error, constantResult);
    	});
		callNextTick(callback, error, constantResult);
    }	

So, here's the implementation:

		function makeCallbackCaller(cb, error, result) {
			return function callbackCall() {
				cb(error, result);
			};
		}

		function callNextTick(cb, error, result) {
			process.nextTick(makeCallbackCaller(cb, error, result));
		}

It's not much. It's just something I don't want to copy from project to project. :)

Tests
-----

Run tests with `make test`.

License
-------

MIT.

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