var sabs;
var done = 0;
onmessage = function(e) {
    var id = e.data[0];
    sabs = e.data[1];
    var how_many = e.data[2];

    if (id == 0) 
        how_many--;     // adjust for copies in main thread

    for (var i = 0; i < how_many; i++) {
        try {
            if (i % 100 == 0) {
                console.log("[" + id + "] "  + (i+1) + " / " + how_many);
            }
            postMessage([sabs, function(){}]);
        } catch (e) {}
    }
    postMessage(id);
}

// loop infinitely, otherwise `sabs` gets freed for some strange reason...
function foo() {
    setTimeout(foo, 10000);
}
foo();

