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

findhit-promise

v0.0.4

Published

javascript promise built on top of findhit-class

Downloads

18

Readme

Promise test-badge

javascript promise built on top of findhit-class

Instalation

npm install findhit-promise --save

Usage


var Promise = require('findhit-promise');

// Implementing on your async function
	
	function async( a1, b1, cb ) {
		// ...

		process.nextTick(function () {
			cb( null, a2, b2)
		})
	};

	async( a1, b1, function ( err, a2, b2 ) {
		// ...
	})

	// Will be

	function async( a1, b1 ) {

		var self = {
			abc: function () {},
			def: function () {},
			fgh: function () {},
		}

		return new Promise(function ( done ) {

			// ...
			if( somethingGoesWrong )
				// You can throw Error, Promise will catch it...
				throw new Error();
				// Or you can send it to done
				// return done( new Error () );

				// Then promise will redirect to right method

			// Otherwise
			done( a2, b2 );
		})
			// If you have more actions on the same environment
			// you can configure them to be chained to this promise by:

				// specifying function
				// .extend( name, fn, context )

				.extend( 'yey', function ( a, b ) {
					return a + b;
				}, self)

				// giving an object with some functions
				// .extend( { name: fn, ... }, context )

				.extend({
					someaction: function ( z ) {
						return new Promise(function () {
							return new Error();
						});
					},
					anotheraction: function ( a ) {
						return new Promise(function () {
							return !! a;
						});
					},
				}, self)

				// Or give an existent instance and the list of keys you want to use
				// This will run thoose functions with the first object as context
				// .extend( context, [ 'methodName', ... ] )

				.extend( self, [ 'abc', 'def' ] )

				.ready()
	};

	// You can:

		// Receive error on a separate function
			
			async( a1, b1 )
				.then(function ( a2, b2 ) {
					// ...
				})
				.error(function ( err ){
					// ...
				})

			// or

			async( a1, b1 )
				.then(function ( a2, b2 ) {
					// ...
				}, function ( err ){
					// ...
				})

		// Always receive err
			
			async( a1, b1 )
				.done(function ( err, a2, b2 ) {
					// ...
				})

		// Chain multiple thens

			async( a1, b1 )
				.then(function ( a2, b2 ) {
					return async( a2, b2 );
				})
				.then(function ( a3, b3 ) {
					return a3 + b3;
				})
				.then(function ( z ) {
					return z;
				})

		// Chain multiple actions

			Promise.all(
			
				async( a1, b1 ),
				async( a2, b2 ),
				async( a3, b3 )
			
			).then(function ( arrayOfResults ) {
				// ...
			})

			Promise.all([
			
				async( a1, b1 ),
				async( a2, b2 ),
				async( a3, b3 ),

			]).then(function ( arrayOfResults ) {
				// ...
			})

		// Or if they provide some action context

			async( a1, b1 ).
			async( a2, b2 ).
			async( a3, b3 ).
				then(function ( arrayOfResults ) {
					// ...
				})


		// since .error catches current promise error, you can also configure a catch all errors
			async( a1, b1 )
				.catch(function ( err ) {
					// ...
				})

Thanks

Huge thanks to Forbes Lindesay.