basic.js 490 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env node
  2. var assert = require('assert');
  3. var qjob = require('../qjobs');
  4. // only 2 jobs in the same time
  5. var q = new qjob({maxConcurrency:2});
  6. var testExecutedJobs = 0;
  7. var myjob = function(args,next) {
  8. setTimeout(function() {
  9. testExecutedJobs++;
  10. next();
  11. },50);
  12. }
  13. // Let's add 10 job and add them to the queue
  14. for (var i = 0; i<10; i++) {
  15. q.add(myjob,['test'+i]);
  16. }
  17. q.on('end',function() {
  18. assert.equal(testExecutedJobs, 10);
  19. });
  20. q.run();