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

async-next

v0.1.14

Published

Async callback manager. Use async.now to run a set of functions in parallel or async.next to run in series.

Downloads

4

Readme

async-next

Async callback manager. Use async.now to run a set of functions in parallel or async.next to run in series.

Install

npm install async-next

Series Example

var Async = require('async-next');
var async = new Async();

async.next(function (next) {
    var count = 0;
    console.log('doing step 1');
    count++;
    next({value: "new value"}, count);
});

async.next(function (next, paramsFromFirstAsyncNext, count) {
    console.log('doing step 2');
    console.log('using passed params: ' + paramsFromFirstAsyncNext.value + " count: " + count);
    next();
});

async.next.start(function () {
  console.log('All done.');
});

Async Example

var async = new Async();
var path = require('path'), fs = require('fs');
var filesToUpdate = [], i;

//build file array to use as test update
for (i=0; i < 3; i++) {
    filesToUpdate.push({path: path.join(__dirname,'./files/file' + i + 'txt'), text: 'New Test Data for file: ' + i})
}

//now run async update
for (i=0; i < filesToUpdate.length; i++){
    async.now(function (next, file) {
        fs.writeFile(file.path,file.text, function(){
            console.log('done updating file: ' + file.path);
            next();
        });
    }, filesToUpdate[i]);
}

async.now.start(function(){
    console.log('Done with Async');
});

Combined async.next and async.now with nesting

var async = new Async();

async.next(function series1 (next){

    //starting a nested async.next will require all nested async calls to complete before the outer async.next will continue;
    async.next(function series1Nested1(next){
        console.log('done with series1Nested1');
        next();
    });

    async.next(function series1Nested2(next){
        console.log('done with series1Nested2');
        next();
    });
      async.next(function series1Nested3(next){
        console.log('done with series1Nested3');

        //calling next() on the last nested async.next will resume the outer async.next
        next();
    });

    //all nested async.next or async.now calls are started on nextTick.  That means their parent function will complete before they start.
    console.log('done with series1');
    //calling the outer async.next after adding nested async.next calls will start them - the outer async.next will continue after the last nested async.next has been called.
    next();
});//end async.next series1

async.next(function series2 (next){
    var path = require('path'), fs = require('fs');
    var filesToUpdate = [], i;

    //build file array to use as test update
    for (i=0; i < 3; i++) {
        filesToUpdate.push({path: path.join(__dirname,'./files/file' + i + 'txt'), text: 'New Test Data for file: ' + i})
    }

    //now run async update
    for (i=0; i < filesToUpdate.length; i++){
        async.now(function (next, file) {
            fs.writeFile(file.path,file.text, function(){
                console.log('done updating file: ' + file.path);
                next();
            });
        }, filesToUpdate[i]);
    }

    async.now.start(function(){
        console.log('done with nested async.now');

        //we need to call the outer next callback for the series2 function to continue our outer async.next series.
        next();
    });

    //all nested async.next or async.now calls are started on nextTick.  That means their parent function will complete before they start.
    console.log('done with series2');
});//end async.next series2

async.next(function series3 (next){
    console.log('done with series3');
    next();
});//end async.next series3

async.next.start(function(){
    console.log('all done with combined example.\n\n');
});

License

MIT