-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples.js
42 lines (30 loc) · 972 Bytes
/
examples.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
var dispatch = require('./lib/dispatch');
// CLASSES
// queue(num_workers);
// task(function, callback_function)
// group()
// create a queue
var linearQueue = dispatch.serialQueue('My Linear Queue');
var concurrentQueue = dispatch.queue(5, 'My Concurrent Queue');
// create a task
var aTask = dispatch.task(function(t) { workHard(); t.done(); });
aTask.on('complete', callback);
// add jobs
queue.push( function(t) {} );
queue.push( aTask );
queue.after(60, aTask);
queue.apply(10, function(t,k) { workWith(k); t.done();} );
// control
queue.suspend();
queue.resume();
queue.on('empty', finalize);
// properties
print("My queue has " + queue.concurrency_count() + " workers.");
// create a group
var aGroup = dispatch.group('Crawlers');
// associate tasks with groups
var groupTask = dispatch.task(function(t) { workHard(); t.done();}, aGroup)
queue.push(aTask);
queue.push(function(t) {work(); t.done();}, aGroup);
// control
group.on('complete', callback);