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

pooch

v0.2.0

Published

Promise flow control similiar to async.

Downloads

7

Readme

Pooch

Promise flow control similar to the popular async module.

Installation

Install with npm

$ npm install --save pooch

Usage

Pooch works with all Promises that follow the ES6 Promise spec. To use on external libraries such as bluebird, just call pooch on the Promise object. You will only need to do this once since require caches objects.

With Node v0.11.17, just a simple require("pooch") will give you the functionality with native promises. Otherwise, you can extend an existing library:

var Promise = require("bluebird"),
	Pooch = require("pooch")(Promise);

API

Documentation

Each of the functions below add to the Promise (or whatever implementation you use with Pooch()) prototype. Each function can also be chained from the root Pooch object (including then). So for example, using thenIf:

Pooch.thenIf(function() { // All it does it return a no-op promise that is always fulfilled.
	return true;
}, function() {
	return anotherPromise();
}).then( ... );

Promise#thenIgnore( Function handler )

Chain a new promise, fulfill it and ignore it's value. It works exactly like Promise#then except the value returned from the original promise is passed on instead of any value return from Promise#thenIf. An example probably illustrates it better.

promiseReturns3().thenIgnore(function(value) {
	console.log(value); // 3
	return promiseReturns4(); // This promise is fullfilled and returns 4
}).then(function(value) {
	// Value is the value fromm promiseReturns3()
	console.log(value); // 3
});

Promise#thenIf( Function condition, Function handler )

Conditional promise execution if a synchronous condition (with the value passed from the previous promise) returns true. The condition callback recieves one parameter, the value from the previously executed promise. The callback is the same callback you would pass to Promise#then.

NOTE: Any value returned from the conditional promise is ignored. If the conditional promise is executed, it just holds up the promise execution chain and waits until it's complete. It has no affect on the ensuing values so any proceeding Promise#then calls receive the value from the promise the Promise#thenIf is attached to effectively skipping the conditional promise. See Promise#thenIgnore.

getUser().thenIf(function(user) {
	return user.age > 18;
}, function(user) {
	return updatePrivacySettings(user);
}).then(function(user) {
	// The user from #getUser
	// Anything returned from updatePrivacySettings promise is ignored.
});

Promise#thenWhile( Function condition, Function callback )

Execute a promise while a condition is true. The condition callback recieves one parameter, the value from the previously executed promise. The callback is the same callback you would pass to Promise#then.

var i = 0;
myPromise().thenWhile(function() {
	return i <= 10;
}, function(value) {
	// `value` is the value from myPromise()
	i++;
    return myOtherPromise();
}).then(function() {
	console.log(i); // 10
});

Testing

Run npm test to run the test suite which is based upon mocha.

License

Created by Adrian Cooney. Licensed under the MIT License.