# @endo/promise-kit

> Helper for making promises

Latest version **1.2.1** (published 2026-04-16) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @endo/promise-kit
pnpm add @endo/promise-kit
yarn add @endo/promise-kit
bun add @endo/promise-kit
```

## Health

**Score 55/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 1.2.1 |
| Published | 2026-04-16 |
| First published | 2022-01-23 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=11.0 |
| Dependencies | 1 |
| Unpacked size | 32.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1053 |
| Author | Endo contributors |
| Maintainers | kriskowal, michaelfig, erights, warner, mhofman, boneskull, naugtur, turadga |
| Keywords | promise |

## Links

- npm: https://www.npmjs.com/package/@endo/promise-kit
- Repository: https://github.com/endojs/endo
- Homepage: https://github.com/endojs/endo#readme
- Issues: https://github.com/endojs/endo/issues
- npm.io page: https://npm.io/package/@endo/promise-kit

## Dependencies (1)

- [@endo/harden](https://npm.io/package/@endo/harden.md) ^1.1.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.2.1 (latest) — 2026-04-16
- 1.2.0 — 2026-02-26
- 1.1.13 — 2025-07-12
- 1.1.12 — 2025-06-17
- 1.1.11 — 2025-06-02
- 1.1.10 — 2025-03-24
- 1.1.9 — 2025-01-24
- 1.1.8 — 2024-11-13
- 1.1.7 — 2024-10-22
- 1.1.6 — 2024-10-10
- 1.1.5 — 2024-08-27
- 1.1.4 — 2024-08-01
- 1.1.3 — 2024-07-30
- 1.1.2 — 2024-05-07
- 1.1.1 — 2024-04-04
- … 36 more at https://npm.io/package/@endo/promise-kit/versions

## README

# Promise Kit

The promise-kit package provides a simple abstraction for creating and managing a promise. It exports, `makePromiseKit` which is a utility function used to create a Promise and its associated resolver and rejector functions. This is particularly useful in asynchronous programming, where you might need to create a promise and resolve or reject it at a later point in time.
Note that this serves as a "ponyfill" for `Promise.withResolvers`, making certain accommodations to ensure that the resulting promises can pipeline messages through `@endo/eventual-send`.

## Usage

Here’s an example of how `makePromiseKit` might be used in an Agoric smart contract or JavaScript program:

### Basic Example

```javascript
import { makePromiseKit } from '@endo/promise-kit';

function asyncOperation() {

  const { promise, resolve, reject } = makePromiseKit();
  setTimeout(() => {
    const success = true; // Simulating success or failure
    if (success) {
      resolve("Operation successful!");
    } else {
      reject("Operation failed!");
    }
  }, 2000); 

  return promise;
}

async function handleAsyncOperation() {
  try {
    const result = await asyncOperation();
    console.log(result); // "Operation successful!"
  } catch (error) {
    console.error(error); // "Operation failed!"
  }
}

handleAsyncOperation();
```

### Creating Multiple Promise Kits

You can create multiple promise kits for managing various asynchronous tasks.

```javascript
const kit1 = makePromiseKit();
const kit2 = makePromiseKit();

kit1.promise.then(value => console.log('Kit 1 resolved with:', value));
kit2.promise.then(value => console.log('Kit 2 resolved with:', value));

kit1.resolve('First success');
kit2.resolve('Second success');

```

## API

### `makePromiseKit()`
Creates a new promise kit.

**Returns**
- **`promise`**: The promise object.
- **`resolve`**: The resolve function for the promise.
- **`reject`**: The reject function for the promise.

## Links
[Repository](https://github.com/endojs/endo/tree/master/packages/promise-kit)

## License
This package is licensed under the Apache-2.0 License.

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