# promiscuous

> A minimal and fast promise implementation

Latest version **0.7.2** (published 2018-09-05) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install promiscuous
pnpm add promiscuous
yarn add promiscuous
bun add promiscuous
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.7.2 |
| Published | 2018-09-05 |
| First published | 2013-01-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 26.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 178 |
| Author | Ruben Verborgh |
| Maintainers | rubenverborgh |

## Links

- npm: https://www.npmjs.com/package/promiscuous
- Repository: https://github.com/RubenVerborgh/promiscuous
- Homepage: https://github.com/RubenVerborgh/promiscuous#readme
- Issues: https://github.com/RubenVerborgh/promiscuous/issues
- npm.io page: https://npm.io/package/promiscuous

## Recent versions

- 0.7.2 (latest) — 2018-09-05
- 0.7.1 — 2017-08-11
- 0.7.0 — 2016-12-01
- 0.6.0 — 2014-01-26
- 0.5.1 — 2014-01-03
- 0.5.0 — 2013-12-31
- 0.4.0 — 2013-12-15
- 0.3.0 — 2013-08-02
- 0.2.0 — 2013-02-03
- 0.1.0 — 2013-01-20

## README

# promiscuous
<a href="http://promises-aplus.github.com/promises-spec">
  <img src="http://promises-aplus.github.com/promises-spec/assets/logo-small.png"
       alt="Promises/A+ logo" title="Promises/A+ 1.0 compliant" align="right" />
</a>

promiscuous is a tiny implementation of the [Promises/A+ spec](http://promises-aplus.github.com/promises-spec/).

It is promise library in JavaScript, **small** (< 1kb [minified](https://raw.github.com/RubenVerborgh/promiscuous/dist/promiscuous-node.js) / < 0.6kb gzipped) and **fast**.

## Installation and usage
### Node
First, install promiscuous with npm.
```bash
$ npm install promiscuous
```

Then, include promiscuous in your code file.
```javascript
var Promise = require('promiscuous');
```

### Browsers
Include [promiscuous](https://raw.github.com/RubenVerborgh/promiscuous/dist/promiscuous-browser.js) in your HTML file.
```html
<script src="promiscuous-browser.js"></script>
```

This version (and a minified one) can be built with:
```bash
$ build/build.js
```

## API
### Create a resolved promise
```javascript
var promise = Promise.resolve("one");
promise.then(function (value) { console.log(value); });
/* one */
```

### Create a rejected promise
```javascript
var brokenPromise = Promise.reject(new Error("Could not keep promise."));
brokenPromise.then(null, function (error) { console.error(error.message); });
/* "Could not keep promise." */
```

You can also use the `catch` method if there is no success callback:

```javascript
brokenPromise.catch(function (error) { console.error(error.message); });
/* "Could not keep promise." */
```

### Write a function that returns a promise
```javascript
function promiseLater(something) {
  return new Promise(function (resolve, reject) {
    setTimeout(function () {
      if (something)
        resolve(something);
      else
        reject(new Error("nothing"));
    }, 1000);
  });
}
promiseLater("something").then(
  function (value) { console.log(value); },
  function (error) { console.error(error.message); });
/* something */

promiseLater(null).then(
  function (value) { console.log(value); },
  function (error) { console.error(error.message); });
/* nothing */
```

### Convert an array of promises into a promise for an array
```javascript
var promises = [promiseLater(1), promiseLater(2), promiseLater(3)];
Promise.all(promises).then(function (values) { console.log(values); });
/* [1, 2, 3] */
```

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