lix-website/themes/lix/assets/bootstrap/node_modules/qjobs/tests/basic.js

29 lines
490 B
JavaScript
Raw Normal View History

2024-04-27 03:39:10 +00:00
#!/usr/bin/env node
var assert = require('assert');
var qjob = require('../qjobs');
// only 2 jobs in the same time
var q = new qjob({maxConcurrency:2});
var testExecutedJobs = 0;
var myjob = function(args,next) {
setTimeout(function() {
testExecutedJobs++;
next();
},50);
}
// Let's add 10 job and add them to the queue
for (var i = 0; i<10; i++) {
q.add(myjob,['test'+i]);
}
q.on('end',function() {
assert.equal(testExecutedJobs, 10);
});
q.run();