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

for-io

v2.0.0

Published

for-io helps you perform async(io) operation on every item in List in more manageable fashion and also helps you keep code clean.

Downloads

12

Readme

for-io

for-io helps you perform async(io) operation on every item in List in more manageable fashion and also helps you keep your code clean.

Installation

$ npm install for-io

How it works

Package exposes two functions which will make your life much easier on handling list. Both does the same thing but in different way i.e parallel and sequential way.

syncFor

Executes callback function on every item in sequential manner.

// importing package
const forio = require("for-io")();

let person1 = {
  firstName : "bob",
  lastName : "backoff"
}
let person2 = {
  firstName: "alice",
  "lastName" : "backoff"
}

var personsList = [person1, person2 ....];

/*
* REQUIREMENT:-
* 1. Calling third party API which accepts one person at one time.
* 2. Stop calling API when there is error with person.
  *
*/
 
forio.syncFor(personList, function(item, index, next){
  api.call(person, function(err, rs){
      next(err, rs);
    });
},function(err){
    // CODE WHEN OPERATION ON LIST FINISHES
});

let me break this down for you

syncFor function accepts three arguments

  • list of item

  • Function you want to execute on each item in array

    This function is called by package with three arguments

    a. item
    b. index of item
    c. next - function when called notifies the library that processing on current item is done.

  • cb/callback function you want to execute when list is traversed successfully. First argument will be error object in case of error otherwise it will be null.
    NOTE:- This callback will be called instantaneously when error is encountered while processing list.

asyncFor

Executes callback function on every item in parallel.

// importing package
const forio = require("for-io")();

let person1 = {
  firstName : "bob",
  lastName : "backoff"
}
let person2 = {
  firstName: "alice",
  "lastName" : "backoff"
}

var personsList = [person1, person2 ....];

/*
*
* REQUIREMENT
* 1. You want to publish messages in queue for each person in list. You will do this parallel.
  *
*/
 
forio.asyncFor(personList, function(item, index, next){
  queue.publish(person, function(err, rs){
    		next(err, rs);
    });
},function(err){
      // CODE WHEN OPERATION ON LIST FINISHES
});

let me break this down for you

asyncFor function accepts three arguments

  • list of item

  • Function you want to execute on each item in array

    This function is called by package with three arguments

    a. item
    b. index of item
    c. next - notifies library that processing on current item is done.

  • cb/callback function you want to execute when every item is traversed successfully. First argument will be array of error in case of error otherwise it will be null.
    NOTE:- In case of error, This will be called after completion of list traverse. It will have error as parameter which will be list of object with index and actual error.

callbackCaller

Returns fn function which after executing n number of times will execute the the callback function you wants to execute.

var forio = require("for-io")();

var person = {
    firstName : "bob",
    lastName : "backoff"
  }

/* 
* REQUIREMENT
  1. You want to perform three different operations parallely
 */
 
var length = personsList.length;

var fn = forio.cbCaller(length, function finalCb(){
    // CODE TO EXECUTE AFTER TWO ASYNC OPERATIONS
});

db.insert(person, function(err, rs){
    fn(err);
});

api.call(person, function(err, rs){
    fn(err);
})

let me break this down for you

callbackCaller accepts two arguments

  • length of array
  • callback function you want to execute when callback caller called n number of times.

cbCaller returns a function fn which called n times will call final callback function.

Development

Want to contribute? Great.

Please leave pull request at github project here for-io

License

MIT