npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ready-promises

v1.1.6

Published

A+, ES6 promises realisation

Downloads

3

Readme

Ready

Ready is a Promises/A+ implementation with supporting ES6 Promises specification.

Promises/A+ specification

Installing

Node.js

Using npm:

npm install ready-promises

Browsers

Using bower:

bower install ready-promises

Using script tag:

<script type="text/javascript" src="ready.min.js"></script>

Simple usage

Using a deferred

var async = function() {
    // create a deferred
    var defer = ready.defer();

    // resolve or reject deferred
    // for example defer.resolve('dummy');

    return defer.promise();
}

async().then(
    function onResolve() {},
    function onReject() {}
);

In this case deferred object contains methods to resolve and reject promise and promise object allow to subscribe on reject and resolve actions

Using ES6 way

var async = function() {
    return new ready.Promise(function(resolve, reject) {
        // you can call resolve or reject callbacks here
    });
}

async().then(
    function onResolve() {},
    function onReject() {}
);

Using as polyfill

Polyfill Promise if there is no another solution (native or other libraries):

ready.polyfill();
/* ...code... */
new Promise(function(resolve, reject) {
    // you can call resolve or reject callbacks here
}).then(function onResolve() {}, function onReject() {});

Polyfill Promise:

ready.polyfill(true);
/* ...code... */
new Promise(function(resolve, reject) {
    // you can call resolve or reject callbacks here
}).then(function onResolve() {}, function onReject() {});

Description

ready methods

Promise(onResolve, onReject) - es6-compatible way to create a promise.

defer() - method to create deferred object.

Deferred() - constructor to create deferred object.

all(iterable) - returns a promise that resolves when all of the promises in the iterable argument have resolved.

race(iterable) - returns a promise that resolves or rejects as soon as one of the promises in the iterable resolves or rejects, with the value or reason from that promise.

any(iterable) - returns first successful promise or returns a promise that rejected when all of the promises in the iterable argument have rejected.

reject(reason) - returns a Promise object that is rejected with the given reason.

resolve(value) - returns a Promise object that is resolved with the given value.

denodeify(fn, argumentCount) - add a callback to any calls to the function, and use that to fullfill or reject the promise.

Deferred object methods

There are two possible ways to create a deferred.

  1. Using method - var defer = reade.defer()

  2. Using constructor - var defer = new ready.Deferred()

Deferred object has 3 methods:

promise - return promise from deferred.

resolve - resolve promise with value

reject - reject promise with reason

Promise object methods

then - add resolve and reject callbacks

done - add resolve callback

fail - add reject callback

catch - add reject callback

nodeify - convert promised code to use node style callbacks. If no callback is provided it will just return the original promise.

all(iterable) - returns a promise that resolves when all of the promises in the iterable argument have resolved.

race(iterable) - returns a promise that resolves or rejects as soon as one of the promises in the iterable resolves or rejects, with the value or reason from that promise.

reject(reason) - returns a Promise object that is rejected with the given reason.

resolve(value) - returns a Promise object that is resolved with the given value.