Skip to content

Some short code to provide a callback when a group of other callbacks all finish.

License

Notifications You must be signed in to change notification settings

elrac/callbacks-done

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

callbacks-done

This is a very simple tool for keeping track of when a set of callbacks is finished in node.

Background

I noticed in node that I would often have the pattern of setting up an object using the results of multiple callbacks. I didn't want to nest the callbacks for many reasons, so I would instead set up a counter that would track the number of callbacks that were run, and run code when when they were all done. I made this so that I didn't have to write that every time.

Usage

var callbacksDone = require('callbacks-done');
var cd = callbacksDone();

var call = function(func){
  func();
}

var print = function(message){
  return function(){
    console.log(message);
  }
}

call(cd.add(print('A')));
cd.onDone(print('Done'));
call(cd.add(print('B')));
call(cd.add(print('C')));
cd.onDone(print('done 2'));

This will print

A

B

C

Done

done 2

About

Some short code to provide a callback when a group of other callbacks all finish.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published