Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A minimal and fast promise/deferred implementation
JavaScript
branch: master

This branch is 10 commits ahead, 37 commits behind RubenVerborgh:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
test
.gitignore
LICENSE.txt
Makefile
README.md
package.json
promiscuous.js

README.md

promiscuous

Promises/A+ logo

promiscuous is a JavaScript promise/deferred implementation, implementing the Promises/A+ spec.

It strives to be minimal (https://raw.github.com/RubenVerborgh/promiscuous/promiscuous.js) and fast.

Installation and usage

Node

First, install promiscuous with npm.

$ npm install promiscuous

Then, include promiscuous in your code file.

var promiscuous = require('promiscuous');

Browsers

Include promiscuous in your HTML file.

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

API

Create a resolved promise

var one = promiscuous.resolve("one");
one.then(console.log);
/* one */

Create a rejected promise

var none = promiscuous.reject("error");
none.then(console.log, console.error);
/* error */

Write a function that returns a promise

function promiseSomething(something) {
  var defer = promiscuous.deferred();
  setTimeout(function () {
    if (something)
      defer.resolve(something);
    else
      defer.reject("nothing");
  }, 1000);
  return defer.promise;
}
promiseSomething("something").then(console.log, console.error);
/* something */
Something went wrong with that request. Please try again.