Last active
August 29, 2015 14:08
-
-
Save hvrauhal/321e2051a4bba294565e to your computer and use it in GitHub Desktop.
It would be nice if this did not consume all memory
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 BPromise = require('bluebird') | |
var i = 0, n = 100000000; | |
function mapManyThings() { | |
return BPromise.map(new Array(1000), function () { | |
return BPromise.delay(1).then(function () { | |
i++ | |
var aThousandFloats = new Array(1000).map(function () { | |
return Math.random() | |
}) | |
return aThousandFloats | |
}) | |
}).then(function (thisShouldBeGCd) { | |
process.stdout.write('\rshould garbage collect: ' + thisShouldBeGCd.length + ' random floats. Processed ' + i + ' batches of random floats') | |
}) | |
} | |
function mapWithoutReferences() { | |
mapManyThings().then(function () { | |
if (i < n) { | |
process.nextTick(mapWithoutReferences) | |
} | |
}) | |
} | |
mapWithoutReferences() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment