Skip to content

Instantly share code, notes, and snippets.

@michaelsbradleyjr
Created September 12, 2011 07:24
Show Gist options
  • Save michaelsbradleyjr/1210750 to your computer and use it in GitHub Desktop.
Save michaelsbradleyjr/1210750 to your computer and use it in GitHub Desktop.
var EventEmitter = require('events').EventEmitter
var continuation = new EventEmitter()
var i = 1
var end = 1000
var doThisManyTimes = function () {
someAsyncFacilityYoureUsing(arg1, arg2 ..., function callback() {
continuation.emit('continue')
})
}
continuation.on('continue', function () {
if (i++ < end) {
doThisManyTime()
}
})
doThisManyTimes()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment