# promise-now

> Barebone Promise/A+ implementation

Latest version **1.1.0** (published 2013-08-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install promise-now
pnpm add promise-now
yarn add promise-now
bun add promise-now
```

## 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.1.0 |
| Published | 2013-08-21 |
| First published | 2013-07-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Glen Huang |
| Maintainers | curvedmark |
| Keywords | promise, promises, promises-a, promises-aplus, async, deferred, future, flow control |

## Links

- npm: https://www.npmjs.com/package/promise-now
- Repository: https://github.com/curvedmark/promise-now
- Issues: https://github.com/curvedmark/promise-now/issues
- npm.io page: https://npm.io/package/promise-now

## 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.1.0 (latest) — 2013-08-21
- 1.0.0 — 2013-08-19
- 0.5.1 — 2013-08-02
- 0.4.1 — 2013-08-02
- 0.4.0 — 2013-08-01
- 0.3.0 — 2013-08-01
- 0.2.2 — 2013-07-31
- 0.2.1 — 2013-07-31
- 0.2.0 — 2013-07-30
- 0.1.0 — 2013-07-30

## README

# promise-now

Barebone [Promise/A+](http://promisesaplus.com/) implementation.

## Features

- Extremely small (~ 1kb minified), [extremely fast](http://jsperf.com/wqfwewefewrw/18)

- `.then()` being asynchronous is optional.

- Passing the [Promises/A+ Compliance Test Suite](https://github.com/promises-aplus/promises-tests)

## Installation

	npm install promise-now

## Example

```javascript
var Promise = require('promise-now');
var promise = new Promise();

promise.then(addOne).then(addOne).then(function(num) {
	console.log(num); // 3
});
promise.fulfill(1);

function addOne(num) {
	return num + 1;
}
```

## API


### promise.then([fulfillCallack], [rejectCallback]);

Call `fulfillCallack(value)` if `promise` is fulfilled with `value`.

Or call `rejectCallback(reason)` if `promise` is rejected with `reason`.

Return a new promise.

### promise.fulfill(value, [context]);

Fulfill `promise` with `value`. `this` keyword equals to `context` in callbacks if provided.

Return original `promise`.

### promise.reject(reason, [context]);

Reject `promise` with `reason`. `this` keyword equals to `context` in callbacks if provided.

Return original `promise`.

### promise.done([fulfillCallack], [rejectCallback]);

Like `.then()`, but throw with reason (asynchronously) if promise is rejected. Should be called at the end of `.then()` chain.

Return `undefined`.

## .then() being asynchronous

If you can be sure that you will never write code like:

```javascript
var promise = new Promise().fulfill();

promise.then(function() {
	console.log(2);
});
console.log(1);
```

In other words, you will not put synchronous code after asynchronous function calls, then it doesn't make a difference if `.then()` is asynchronous or not.

By default, promise-now use synchronous `.then()`. If you need the asynchronous version, simply patch promise-now (see `test/promise.js` on how it's done).

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