Created
October 12, 2010 14:06
-
-
Save yssk22/622213 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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