-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
43 lines (38 loc) · 2.16 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var dispatch = require('./lib/index');
// CLASSES
// queue(num_workers);
// task(function, callback_function)
// group()
// create a queue
var linearQueue = dispatch.serialQueue('My Linear Queue');
var concurrentQueue = dispatch.queue('My Concurrent Queue', 5);
var workGroup = dispatch.group("Work Group");
// create a task
linearQueue.push(function(task) {
console.log("Starting Task w/ object");
console.log(task);
console.log("*******");
setTimeout(function() {
task.done();
}, 2000);
});
linearQueue.push(function(task) { setTimeout(function() {task.done();}, 2000);});
linearQueue.push(function(task) { setTimeout(function() {task.done();}, 2000);});
linearQueue.push(function(task) { setTimeout(function() {task.done();}, 2000);});
linearQueue.push(function(task) { setTimeout(function() {task.done();}, 2000);}, workGroup);
linearQueue.push(function(task) { setTimeout(function() {task.done();}, 2000);});
concurrentQueue.push(function(task) { setTimeout(function() {task.done();}, 2000);});
concurrentQueue.push(function(task) { setTimeout(function() {task.done();}, 2000);});
concurrentQueue.push(function(task) { setTimeout(function() {task.done();}, 2000);});
concurrentQueue.push(function(task) { setTimeout(function() {task.done();}, 2000);});
concurrentQueue.push(function(task) { setTimeout(function() {task.done();}, 2000);});
concurrentQueue.push(function(task) { setTimeout(function() {task.done();}, 2000);});
concurrentQueue.push(function(task) { setTimeout(function() {task.done();}, 2000);});
concurrentQueue.push(function(task) { setTimeout(function() {task.done();}, 2000);});
concurrentQueue.push(function(task) { setTimeout(function() {task.done();}, 2000);});
concurrentQueue.push(function(task) { setTimeout(function() {task.done();}, 3000);}, workGroup);
concurrentQueue.push(function(task) { setTimeout(function() {task.done();}, 2000);});
concurrentQueue.push(function(task) { setTimeout(function() {task.done();}, 2000);});
linearQueue.on('empty', function() { console.log("Linear queue empty."); });
concurrentQueue.on('empty', function() { console.log("Concurrent queue empty."); });
workGroup.on('complete', function() { console.log("Work group complete.");});