И стаковерфлов о них: http://stackoverflow.com/questions/21017329/could-i-execute-function-right-before-closure-death-garbage-collection

function getRandomInt(min, max)
{
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

var server = require('http').createServer(function(request, response)
{
    var atEnd = function()
    {
        response.end('No more randoms for you.')
    };

    (function(){    

        response.statusCode = 200;
        response.setHeader('Content-Type','text/html; charset=UTF-8');

        // This loop is emulating a huge sophisticated complex async
        // callback delirium which cannot be easily understood and
        // tracked down, and I won't get paid for its refactoring.
        for(var i = 0;i < getRandomInt(0,getRandomInt(0,1000)); i++)
        {
            setTimeout(function()
            {
                response.write(String(getRandomInt(0,1000) + "<br/>"))
            },getRandomInt(0,30000))
        }

    //  What I'd wish to do:
    //  require('some-cool-module').onClosureDeath(atEnd)

    })()
}
).listen(11111);
[ ]
 

P.S. Присылайте криптовалюту если вам нравится то, что я делаю.
Если не нравится - тоже присылайте.
LTC (Litecoin): LLN6X2uV1iuQ1e4tdmQZsf2RRwh4pxPSej

Leave a Reply

*