tj / co-parallel

Execute thunks in parallel with concurrency support
109 stars 9 forks source link

support real concurrency #3

Closed dead-horse closed 10 years ago

dead-horse commented 10 years ago
var block = true;
function get() {
  return function (done) {
    setTimeout(done, block ? 100 : 5);
    block = false;
  };
}

co(function *() {
  var tasks = [];
  for (var i = 0; i < 200; i++) {
    tasks.push(get());
  }
  var start = Date.now();
  yield parallel(tasks, 10);
  console.log('total used %dms', Date.now() - start);
})();

now it won't block by one slow request. the sample total use from 230ms decrease to 160ms

tj commented 10 years ago

thanks!

dead-horse commented 10 years ago

these code write at midnight just like shit. lol