# p-defer

> Create a deferred promise

Latest version **4.0.1** (published 2024-04-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install p-defer
pnpm add p-defer
yarn add p-defer
bun add p-defer
```

## Health

**Score 45/100 (D)** — status: abandoned.

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

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 4.0.1 |
| Published | 2024-04-01 |
| First published | 2016-10-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=12 |
| Dependencies | 0 |
| Unpacked size | 3.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 87 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | promise, defer, deferred, resolve, reject, lazy, later, async, await, promises |

## Links

- npm: https://www.npmjs.com/package/p-defer
- Repository: https://github.com/sindresorhus/p-defer
- Homepage: https://github.com/sindresorhus/p-defer#readme
- Issues: https://github.com/sindresorhus/p-defer/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/p-defer

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

- 4.0.1 (latest) — 2024-04-01
- 4.0.0 — 2021-04-09
- 3.0.0 — 2019-06-07
- 2.1.0 — 2019-04-03
- 2.0.1 — 2019-03-23
- 2.0.0 — 2019-03-17
- 1.0.0 — 2016-10-21

## README

# p-defer

> Create a deferred promise

[Don't use this unless you know what you're doing.](https://github.com/petkaantonov/bluebird/wiki/Promise-anti-patterns#the-deferred-anti-pattern) Prefer the `Promise` constructor.

## Install

```sh
npm install p-defer
```

## Usage

```js
import pDefer from 'p-defer';

function delay(milliseconds) {
	const deferred = pDefer();
	setTimeout(deferred.resolve, milliseconds, '🦄');
	return deferred.promise;
}

console.log(await delay(100));
//=> '🦄'
```

*The above is just an example. Use [`delay`](https://github.com/sindresorhus/delay) if you need to delay a promise.*

## API

### pDefer()

Returns an `object` with a `promise` property and functions to `resolve()` and `reject()`.

## Related

- [p-lazy](https://github.com/sindresorhus/p-lazy) - Create a lazy promise that defers execution until `.then()` or `.catch()` is called
- [More…](https://github.com/sindresorhus/promise-fun)

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