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

callbaq

v2.1.0

Published

Convert nested callback hell into serial procedural coding style, which is more readable, writable, and maintainable. Lightweight, Zero Dependency.

Downloads

10

Readme

Callbaq

FOSSA Status

NAME

Callbaq - A callback queue for workflow control.

Lightweight, Zero Dependency.

SYNOPSIS

var Callbaq = require('callbaq');
var workflow = new Callbaq();

// kickoff
workflow.start("new world!");

// add callback functions
workflow.add(function (cbq, input) {
        console.log("1: hello world : " + input);
        cbq.next("y0y0");
});
workflow.add(function (cbq, input) { console.log("2: here we go : " + input); });

// output:
// 1: hello world : new world!
// 2: here we go : y0y0

Or fire it later, also try using aliases methods

// add callback functions
workflow.add(function (cbq, input) {
        console.log("1: hello world : " + input);
        cbq.resolve("y0y0");
});
workflow.then(function (cbq, input) {
        console.log("2: here we go : " + input);
        return "knock knock";
});
// fire
var door = workflow.start("new world!");

// output:
// 1: hello world : new world!
// 2: here we go : y0y0
// content of door: "knock knock"

DESCRIPTION

callbaq is a lightweight callback queue for workflow and callback control with Zero Dependency.
Convert nested callback hell into serial procedural coding style, which is more readable, writable, and maintainable.

Work standalone, or with other modules.

INSTALLATION

npm i callbaq

METHODS

new

Get a new callback queue / flow.

var Callbaq = require('callbaq');
var callbaq = new Callbaq();

start

Start and walk through the workflow from step 0.

callbaq.start("new world!");

add / then

Add (append) a function for use as a callback, which will be executed at the next step.

The parameters for callback are:

  1. callbaq instance of the current callback queue.
  2. params from start() or the output of previous (step) callback function.
callbaq.add(function (cbq, input) {
        console.log("something cool : " + input);
        cbq.next("a secret");
});
callbaq.then(function (cbq, input) {
        console.log("finished with " + input);
});

next / resolve

Check out from the current step and pass result to next step / callback function when works are done.

callbaq.add(function (cbq, input) {
        cbq.resolve("A master piece");
});
callbaq.then(function (cbq, input) {
        cbq.next("A master piece");
})

EXPERIMENTAL use of Methods

The following methods are for EXPERIMENTAL usage and might change in the future.

Avoid using them if possible.

cbq

Similar to add(). Returns the queue array.
If called with a function object, the function object will be append into queue.

var old_queue = callbaq.cbq();
var new_queue = callbaq.cbq(function(cbq){ cbq.next("did something") });

current_step

Get or set current step number.
Workflow could be changed by calling this method with value.

var current_step_number = cbq.current_step();

// start over from the first step
var new_step_number = cbq.current_step(0);
cbq.next("some params");

step

Call specific step.

callbaq.step(3, "some params");

ATTRIBUTES

The following methods are for EXPERIMENTAL usage and for Expert Only, might change in the future.

Avoid accessing them directly if possible.

dataqueue

The queue of data awaiting for being input of callback functions, Array of any.

_cbq

The callback queue, Array of function.

_current_step

Current step, in number.

Create with custom initial values

var dataqueue = [1, 2];

// new with default values
var callbaq = new Callbaq({dataqueue: dataqueue});
callbaq.add(function (cbq, input) {
        console.log("something in data queue: ", input);
});
// will be executed immediately without needing callbaq.start()

EXAMPLES

You can have multiple callbaq instances working together or independently.

Just new some and enjoy them.

https://github.com/BlueT/callbaq/blob/master/example.js

Output:
	cb1, step 1: hello world :  [ 'new world!' ]
v->	cb1, step 2: here we go :  [ 'y0y0' ]
|	----------
|	cb2, step 1: Are you ok : bro
|	---> inner1: asking bro
|	---> inner2: he's fine
|	cb2, step 2: I am very ok : Let's rock N roll
|	----------
^->	cb1, step 3: here we go :  [ 'hEy Lo' ]
	----------
	something in data queue:  1
	and guess what!  [ 'lala' ]
	from dataqueue again!  2

AUTHOR

BlueT - Matthew Lien - 練喆明 [email protected]

CREDITS

Waiting for Your Name here.

BUGS

https://github.com/BlueT/callbaq/issues

CONTRIBUTE

You can do a Fork, fix bug or improve code, and send a PR.
Or you can file a issue for bugs or improvements.

If you find this module useful, please give me a Star, I'll be happy whole day.

Hope this module can save your time, a tree, and a kitten.

SEE ALSO

AnyEvent::CallbackStack - Perl version https://github.com/BlueT/AnyEvent-CallbackStack

License

FOSSA Status