Created
March 8, 2013 22:11
-
-
Save mojodna/5120323 to your computer and use it in GitHub Desktop.
Concurrent workers.
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
"use strict"; | |
var d3 = require("d3"); | |
var WORKERS = 5; | |
var worker = function(complete) { | |
var doWork = function() { | |
return done(); | |
}; | |
function done() { | |
process.nextTick(doWork); | |
} | |
return doWork; | |
}; | |
var running = 0; | |
var startWorker = function() { | |
worker(function() { | |
running--; | |
})(); | |
running++; | |
}; | |
d3.range(0, WORKERS).forEach(function(i) { | |
startWorker(); | |
}); | |
var progress = setInterval(function() { | |
process.stdout.write("\n"); | |
console.log("----------------------"); | |
console.log("Workers: %d", running); | |
console.log("----------------------"); | |
// start workers back up if they've stopped | |
while (running < WORKERS) { | |
startWorker(); | |
} | |
}, 30000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment