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

bucks

v0.8.4

Published

Async utilities for node and the browser. (amd support)

Downloads

253

Readme

bucks.js

Async chain utility for node and the browser. (amd support)

Build

dependence) node.js

$ npm install .

$ make

Examples

add and end

add is general way to add a task to bucks object. end starts executing added tasks. Results and errors can be passed to next task in various way.

task is generally task(err, res, next) form function. next task waits until next is called in previous task. if next is not specified, next task is called immediately with returned value.

//
// new Bucks object
//
var b = new Bucks();

//
// Add and add several tasks.
//
b.add(function f1(err, res) {

    return 'a';

}).add(function f2(err, res, next) {

    // res => 'a'
    return next(null, 3);

}).add(function f3(err, res, next) {

    // res => 3
    return next(new Error('error after 3'));

}).add(function f4(err, res, next) {

    // err => 'error after 3'
    return next(null, "recover 4");

}).add(function f5(err, res) {

    // res => 'recover 4'
    throw new Error('error in f5');

}).add(function f6(err, res) {

    // err => 'error in f5'
    throw err;

}).add(function f7(err, res) {

    // err => 'error in f5'
    // ignore and return
    return "recover 7";

}).add(function f8(err, res, next) {

    // res => 'recover 7';
    throw new Error('error in f8');

}).add(function f9(err, res, next) {

    // err => 'Error in f8'
    // ignore error
    return next(null, 'result of 9');

}).end(function last(err, results) {

    // all of results
    // are obtained in #end

    // err => null

    // results => [
    //     'a',
    //     null,
    //     null,
    //     'recover 4',
    //     null,
    //     null,
    //     'recover 7',
    //     null,
    //     'result of 9'
    // ];
});

then

then adds a task called only in case of success

b = new Bucks();
b.then(function start() {
    return 'start';
}).then(function second(res, next) {
    // res => 'start'
    return next(null, 'second')
}).end();

delay

delay add delay execution

b = new Bucks();
b.add(function (){ /** program */ })
.delay(1 * 1000) // 1ms
.add(function() { /** program */})
.end();

error

error adds a task called only in case of error

b.then(function start() {
    throw new Error('error in start');
    return 'start';
}).error(function onError(e, next) {
    // e => 'error in start'
    return next();
}).end();

final errorback in end

Second param in end works as final errorback.

//
// last error back
//
b = new Bucks();
b.empty(
    // add empty task (#end with no task cause error)
).end(function last(err, res) {
    // error in last callback
    throw new Error('error in end');
}, function finalErrorback(err) {
    // catch uncaught error in last callback
    // err => 'error in end'
});

uncaught error

uncaught errors properly thrown to outside of chain.

try {
    var b = new Bucks();
    b.then(function () {
        throw new Error('error');
    }).end();
} catch(e) {
    // e => 'error'
}

waterfall

waterfall is another way to add several tasks.

var t1 = function t1(err, res) {
    return 't1';
};
var t2 = function t2(err, res) {
    return 't2';
};

new Bucks.waterfall([t1, t2]).end(function finish(err, ress) {
    // ress => ['t1', 't2']
});

// same as
new Bucks.add(t1).add(t2).end(function finish(err, ress) {
    // ress => ['t1', 't2']
});

parallel

parallel executes tasks in asynchronous way and join their results


b = new Bucks();

b.parallel([
    function task1(err, res) {
        return "task1";
    },
    function task2(err, res, next) {
        return next(null, "task2");
    },
    function task3(err, res, next) {
        return next(new Error('passed error in task3'));
    },
    function task4(err, res, next) {
        throw new Error('thrown error in task4');
    }
]).add(function getResults(err, res, next) {
    // res => {
    //     err: [
    //         null,
    //         null,
    //         [Error: passed error in task3],
    //         [Error: thrown error in task4]
    //     ],
    //     res: [
    //         'task1',
    //         'task2',
    //         null,
    //         null
    //     ]
    // }
    next();
}).end();

onError

onError Function to handle exceptions that have not been processed

var onError = function (e, bucks) {
    console.log("Custom onError");
};

// Bucks.onError!!
Bucks.onError(onError);
var b0 = new Bucks();
b0
    .add(function(err, next) {
        throw new Error('b0');
    })
    .end()
;

dispose

var b0 = new Bucks();

b0.dispose = function dispose () {
    delete b0.dummy;
}

b0
    .add(function(err, next) {
        b0.dummy = "dummy";
        next();
    })
    .end(null, null)
;

DEBUG

The output debug log

Bucks.DEBUG = true;

AUTHORS

Kei FUNAGAYAMA

Kazuma MISHIMAGI

CyberAgent Publicity

Changelog

@see https://github.com/CyberAgent/bucks.js/blob/master/Changelog

Copyright

CyberAgent, Inc. All rights reserved.

License

MIT @see https://github.com/CyberAgent/bucks.js/blob/master/LICENSE

Bitdeli Badge