# async-compat

> Compatibility functions for writing libraries that support synchronous, callback and promise signatures

Latest version **1.8.4** (published 2026-09-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install async-compat
pnpm add async-compat
yarn add async-compat
bun add async-compat
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.8.4 |
| Published | 2026-09-12 |
| First published | 2020-04-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=0.8 |
| Dependencies | 2 |
| Unpacked size | 39.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Kevin Malakoff |
| Maintainers | kmalakoff |
| Keywords | async, compatibility, library, callback, promise |

## Links

- npm: https://www.npmjs.com/package/async-compat
- Repository: https://github.com/kmalakoff/async-compat
- Issues: https://github.com/kmalakoff/async-compat/issues
- npm.io page: https://npm.io/package/async-compat

## Dependencies (2)

- [is-error](https://npm.io/package/is-error.md) ^2.0.0
- [is-promise](https://npm.io/package/is-promise.md) ^4.0.0

## 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

- 1.8.4 (latest) — 2026-09-12
- 1.8.3 — 2026-05-26
- 1.8.2 — 2026-05-26
- 1.8.1 — 2025-12-19
- 1.8.0 — 2025-12-15
- 1.7.9 — 2025-12-12
- 1.7.8 — 2025-12-12
- 1.7.7 — 2025-12-04
- 1.7.6 — 2025-12-04
- 1.7.5 — 2025-12-02
- 1.7.4 — 2025-11-06
- 1.7.3 — 2025-10-21
- 1.7.2 — 2025-10-21
- 1.7.1 — 2025-07-08
- 1.7.0 — 2025-06-29
- … 34 more at https://npm.io/package/async-compat/versions

## README

# async-compat

Convert synchronous, callback, and promise-returning functions to a callback interface.

## Install

```bash
npm install async-compat
```

## Usage

`asyncFunction(fn, hasCallback, ...args, callback)` invokes `fn` and calls the final callback with `(err, result)`. Set `hasCallback` to `true` when `fn` expects a callback.

```js
var compat = require('async-compat');

function syncFn(value) {
  return value * 2;
}

compat.asyncFunction(syncFn, false, 2, function (err, result) {
  if (err) throw err;
  console.log(result); // 4
});

function callbackFn(value, callback) {
  callback(null, value * 2);
}

compat.asyncFunction(callbackFn, true, 2, function (err, result) {
  if (err) throw err;
  console.log(result); // 4
});

function promiseFn(value) {
  return Promise.resolve(value * 2);
}

compat.asyncFunction(promiseFn, false, 2, function (err, result) {
  if (err) throw err;
  console.log(result); // 4
});
```

## API

- `asyncFunction(fn, hasCallback, ...args, callback)` normalizes a synchronous, callback-based, or promise-returning function. Returned `Error` values and rejected promises reach the callback as `err`.
- `asyncValue(value, callback)` sends an `Error`, resolved promise value, or ordinary value to the callback.
- `defaultValue(result, value)` returns `value` only when `result` is `undefined`; otherwise it returns `result`.

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