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

callback-stack

v1.2.0

Published

Small library for creating group of callback and reacting on all their execution

Downloads

14

Readme

callback-stack for NodeJS

callback-stack is NodeJS module for creating groups of callbacks and reacting on all their execution

##Installation Use NPM to install this module:

$ npm install callback-stack

##Example


const CS = require('callback-stack'); //Explanation is not needed, yeah?

var cstack = new CS(); //Create new empty stack
cstack = new CS(1); //Or maybe you want to tell constructor how much callbacks you need?

//Add 'on all callbacks executed' callback
cstack.then(() => { 
	console.log('All callbacks executed successfully');
});

//And error catching callback (catching error that generated callback got & from your 'on all callbacks executed' callbacks)
cstack.catch((err) => {
	console.log('Error: ' + err.message);
});

//Set how frequently (im milliseconds) checks for complecity will be performed
cstack.checkEvery(666);
	
//Create new callback and execute it (newCallback returns created callback)
//After that, .then callback(s) will be executed, because there's only one added to stack callback
cstack.newCallback()('useless text');

//Reset executions count, so you can reuse object again
cstack.reset(); 

//You do not need index to get function, because the secret of module is - there's only one callback function
//Get and execute function with error passed
//This will call .catch callback(s) with error passed to them
cstack.getCallback()(new Error('Test cool error catching'));
cstack.reset();

//You can use 'newCallbacks' for increasing count of callbacks more than by 1
cstack.newCallbacks(3).forEach((cb) => {
	cb();
});

cstack.reset();
//Our object also have it's own forEach with index so you can use it like for-each loop
cstack.forEach((cb, i) => {
	console.log('Executing callback #' + i);
	cb();
});

cstack.reset();

//And you ofcourse can just get whole stack as array
cstack.getCallbacks().forEach((cb) => {
	console.log('Executing callback');
	cb();
});

//And ofcourse you can do things like this
//Most of functions return stack obj so it allows you to build structures like this
var cstack2 = new CS(1).checkEvery(10000).then(() => {
	console.log('Success');
}).catch((err) => {
	console.log('Error: ' + err.message);
}).forEach((cb, i) => {
	fs.readFile();
	cb();
});