Skip to content
This repository has been archived by the owner. It is now read-only.
An old and obsolete Promise experiment for pre-ES6 JavaScript
Branch: master
Clone or download

Promiscuous was a 2013 experiment to make a tiny library with full Promise compatibility. JavaScript has drastically changed since: we now have Promises (nearly) everywhere, and transpilation with full-fledged shims for cases where we don't.

So please, do not use this library anymore. Look into Babel and webpack when developing for pre-ES6 targets.


Promises/A+ logo

promiscuous is a tiny implementation of the Promises/A+ spec.

It is promise library in JavaScript, small (< 1kb minified / < 0.6kb gzipped) and fast.

Installation and usage


First, install promiscuous with npm.

$ npm install promiscuous

Then, include promiscuous in your code file.

var Promise = require('promiscuous');


Include promiscuous in your HTML file.

<script src="promiscuous-browser.js"></script>

This version (and a minified one) can be built with:

$ build/build.js


Create a resolved promise

var promise = Promise.resolve("one");
promise.then(function (value) { console.log(value); });
/* one */

Create a rejected promise

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:

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

Write a function that returns a promise

function promiseLater(something) {
  return new Promise(function (resolve, reject) {
    setTimeout(function () {
      if (something)
        reject(new Error("nothing"));
    }, 1000);
  function (value) { console.log(value); },
  function (error) { console.error(error.message); });
/* something */

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

Convert an array of promises into a promise for an array

var promises = [promiseLater(1), promiseLater(2), promiseLater(3)];
Promise.all(promises).then(function (values) { console.log(values); });
/* [1, 2, 3] */
You can’t perform that action at this time.