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

venqueuer

v1.3.1

Published

An javascript asynchronous code enqueuer. Perfect for queue up repetitive i/o tasks that should be executed in order, in a way that the end of one task calls the next in the queue, all this asynchronously, of course. You just need to register the function

Downloads

5

Readme

vEnqueuer

An javascript asynchronous code enqueuer. Perfect for queue up repetitive i/o tasks that should be executed in order, in a way that the end of one task calls the next in the queue, all this asynchronously, of course. You just need to register the function which you want queue up and call vEnqueuer's methods like enqueue or trigger.

Install vEnqueuer

npm install venqueuer --save

How to use

    var vEnqueuer = require('venqueuer');
    var venqueuer = new vEnqueuer();
  

Creating a queue

With vEnqueuer, it's possible to create multiple queues, each one responsible for managing specific tasks. For instance, we can create a 'download' queue, and a 'unzip' queue. In the download's queue we want to queue up just download tasks, and we'd like to call unzip tasks just after all downloads have been completed. The code below does just that:

    venqueuer.createQueue("unzip", function(){
  		console.log("all files unzipped!");
  	});
  	
  	venqueuer.createQueue("download", function(){
	        console.log("all downloads have been completed!");
        vEnqueuer.trigger("unzip");
    });	
    

By now, we have just created queues and set callback functions to them. These callback functions tells the queue what to do when all its tasks are completed. Let's say we want to download 3 files in a predefined order:

    downloadLinks.forEach(function(l){
        venqueuer.enqueue("download", downloadFn, { //downloadFn is a reference to download's function
            
            url: l,  //url is an argument required by the downloadFn
            dest: './folder', //dest is an argument required by the downloadFn
            
            //callback is the callback which will be used by downloadFn when download completes
            callback: function(err){  //an error argument is passed in case of error during download
              if(err){
                console.log("an error occurred", err);
                return;
              }
              console.log("successful download");
              
              //some code to enqueue unzip task...
              
            }
            
        });
        
        if( isLastIteration() ){
            //initiate queued tasks when the list has been traversed
            venqueuer.trigger("download");
            
        }
        
    });
    

From now, you may understand vEnqueuer and is fully capable of complete the //some code to enqueue unzip task.

This binding

Bind a 'this' object to the task function its really simple, you just need to pass the 'this' object as an extra attribute called self in your literal object:

    venqueuer.enqueue("download", downloadFn, { 
          self:someObject, 
          url: l, 
          dest: './folder', 
          callback: function(err){...}
    });