Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

promiscuous

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promiscuous

A minimal and fast promise implementation


Version published
Weekly downloads
5.3K
increased by40.19%
Maintainers
1
Weekly downloads
 
Created
Source

promiscuous

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

Node

First, install promiscuous with npm.

$ npm install promiscuous

Then, include promiscuous in your code file.

var Promise = require('promiscuous');

Browsers

Include promiscuous in your HTML file.

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

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

$ build/build.js

API

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

var promises = [promiseLater(1), promiseLater(2), promiseLater(3)];
Promise.all(promises).then(function (values) { console.log(values); });
/* [1, 2, 3] */

FAQs

Package last updated on 26 Jan 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc