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

bond

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bond

A minimal Promises A implementation

  • 0.1.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
19
decreased by-9.52%
Maintainers
1
Weekly downloads
 
Created
Source

Bond - A Simple CommonJS Promises Implementation

Bond is a simple implementation of the Promises/A specification.

It allows authors to write promise-compatible methods; which in turn allow users to add multiple functions to call on "success" or "failure" of the original call.

Example

// This is a promise-compatible method that
// waits for 10 milliseconds and then keep
// or break the promise depending on the
// 'pass' argument.
var wait10millis = function(pass) {
    var dfd = bond.deferred();
    setTimeout(function() {
        if ( pass ) {
            dfd.resolve();
        } else {
            dfd.reject();
        }
    }, 10);
    // promise methods must return a promise
    return dfd.promise();
};


// USAGE EXAMPLES:

// single "then()" (or 'success')
wait10millis(true).then(function() {
    alert('yay');
});

// single "then()", single "fail()":
wait10millis( (Math.rand()>0.5) )
    .then(function() { alert('yay'); })
    .fail(function() { alert('boo'); });

// keep the promise to add more methods later
var promise = wait10millis( (Math.rand()>0.5) );
// NB - this will all happen long after the 10 millis
setTimeout(function() {
    promise.then(function() { alert('hi'); });
    promise.then(function() { alert('ho'); });
    promise.fail(function() { alert('no'); });
    promise.fail(function() { alert('go'); });
}, 100);

FAQs

Package last updated on 24 Apr 2012

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