Skip to content

Instantly share code, notes, and snippets.

@adohe-zz
Created May 14, 2014 15:12
Show Gist options
  • Select an option

  • Save adohe-zz/cc1521c74ccd2665a670 to your computer and use it in GitHub Desktop.

Select an option

Save adohe-zz/cc1521c74ccd2665a670 to your computer and use it in GitHub Desktop.
event pub&sub in Node.js
/**
* Event_pub_sub with many to one
*
*/
var after = function (times, callback) {
var count = 0,
results = {};
return function (key, value) {
results[key] = value;
count ++;
if (count === times) {
callback(results);
}
};
}
// Usage
var done = after(2, render);
fs.readFile('', function (err,data) {
done('template', data);
});
db.query('', function (err, db) {
done('db', db);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment