async breakout
## coffee --nodejs --expose-gc index.coffee
###
sam autor asyncu pise ze se to ma udelat takhle
https://github.com/caolan/async/pull/85#issuecomment-13072390
or just use a named function for the final callback and call that instead
of the task callback passed into the successful task function.
###
mem = () -> Math.floor(process.memoryUsage().rss / 1024 / 1024)
logmem = (o) -> console.log mem() + " MB " + o + " " + (mem() - startmem ) + " MB"
startmem = mem()
async = require 'async'
test = (testdone) ->
logmem "pred taskama"
tasks = []
tasks.push i for i in [1..10000000]
logmem "tasky v pameti"
findSeries = (series, done) ->
async.eachSeries series, (s, next) ->
return done null, s if s is 10 # vyskocim z asyncu kdykoliv potrebuju
setTimeout (() -> next()), 0
, done
findSeries tasks, () ->
console.log arguments
testdone()
test () ->
logmem 'tesne po dobehnuti'
setInterval () ->
global.gc()
logmem 'po gccku'
, 1000