Skip to content

Instantly share code, notes, and snippets.

@yssk22
Created October 12, 2010 14:06
Show Gist options
  • Save yssk22/622213 to your computer and use it in GitHub Desktop.
Save yssk22/622213 to your computer and use it in GitHub Desktop.
var sys = require('sys');
var EventEmitter = require('events').EventEmitter;
var MAX = 1000000;
var c = 0;
function doOnce(){
require('assert').equal(c, MAX);
console.log('OK');
}
function async(){
var ev = new EventEmitter();
setTimeout(function(){
c = c + 1;
ev.emit('done');
}, (Math.random() * 100 % 10) * 100);
return ev;
}
for(var i=0; i<MAX; i++){
(function(){
var ev = async();
ev.on('done', function(){
if(c == MAX){
doOnce();
}
});
})();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment