Skip to content

Instantly share code, notes, and snippets.

@falsecz
Created April 23, 2015 20:37
Show Gist options
  • Save falsecz/f0be5e54d3cf8bf2e6e1 to your computer and use it in GitHub Desktop.
Save falsecz/f0be5e54d3cf8bf2e6e1 to your computer and use it in GitHub Desktop.
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
@falsecz
Copy link
Author

falsecz commented Apr 23, 2015

24 MB pred taskama 0 MB
166 MB tasky v pameti 142 MB
{ '0': null, '1': 10 }
166 MB tesne po dobehnuti 142 MB
24 MB po gccku 0 MB
24 MB po gccku 0 MB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment