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

concurrency

v0.1.4

Published

A way to achieve concurrency running multiple tasks

Downloads

4,774

Readme

Concurrency

This package provides dependency mangement for child procecesses and callbacks. It also allows you to create custom tasks that may then be added as a dependency elsewhere.

Installing

npm install concurrency

Example Usage

var concurrency = require('concurrency');
var Callback    = concurrency.Callback;
var Process     = concurrency.Process;

var find = new Process({
   command:"find",
   args:["/bin"]
});
var find2 = new Process({
   command:"find",
   args:["/usr/bin"]
});

var callback = new Callback(function(done, find, find2){
    var i = setInterval(function(){
        console.log('waiting...');
    }, 500);
    //let's write them to stdout for fun...
    find.stdout.pipe(process.stdout);
    find2.stdout.pipe(process.stdout);

    //we better give the pipes enough time to drain ;)
    setTimeout(function(){
        clearInterval(i);
        console.log('callback finished!');
        done("'I feel like yielding now :)'");
    }, 10000);
}).follows(find).follows(find2);

var ls = new Process({
   command:"ls"
}).follows(callback);

find.on('running', function(){
    console.log('find running');
});
find.on('complete', function(){
    console.log('find complete');
});
find2.on('running', function(){
    console.log('find2 running');
});
find2.on('complete', function(){
    console.log('find2 complete');
});

ls.on('complete', function(ls){
    console.log('ls complete');
    ls.stdout.pipe(process.stdout);
});

ls.on('running', function(callback){
    console.log("The yield of the callback was: "+callback.yield);
    console.log('ls running');
});

ls.run();

Custom Tasks

The source for Callback says it best:

var Task          = require('./Task');

module.exports = Callback;
Callback.prototype=new Task;
Callback.prototype.constructor=Callback;
Callback.prototype.yield=null;

/**
 * @constructor
 * @param {function(function(value), ...[Task])} fn Receives a callback and the
 * followed [Task[s]].  The value given to the callback becomes the yield on the
 * Callback and when called signals the 'complete' event on the Callback.
 * @returns {Callback}
 */
function Callback(fn){
    this.initialize();
    var task = this;
    var _yield=null;
    var notRun=true;

    if(typeof fn !== 'function'){
        throw new Error("fn must be a function");
    }

    Object.defineProperty(this, 'yield', {
        get:function(){return _yield;},
        enumberable:true
    });

    task.on('running', function(){
        var yielder;
        if(notRun){
            notRun=false;
            yielder=function(value){
                _yield=value;
                task.emit('complete');
            };
            fn.apply(task, [yielder].concat([].slice.apply(arguments)));
        }
    });
}

License

 Copyright 2013 Joseph Spencer.
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
 
       http://www.apache.org/licenses/LICENSE-2.0
 
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.

Bitdeli Badge