/
stack.messages.js
75 lines (55 loc) · 1.47 KB
/
stack.messages.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
ToolStack.MQ = (function(ts){
var util = ts.Utility,
ds = ts.Structures,
q = {},
dq = ts.DelayQueue = function(ms,parrallel){
var q = {
queue: ds.Queue(),
parrallel: parrallel || false,
paused: false,
flushed: false,
timer: null,
delay:ms,
active: true,
maxpool: 200,
};
q.isPending = function(){ return !!this.pending; };
q.maxOut = function(){
if(!this.pending && this.queue.length) return false;
return true;
};
q.resume = function(){
if(this.paused()) return;
this.paused = false;
};
q.pause = function(){
if(!this.paused) this.paused = true;
};
q.isPaused = function(){ return !!this.paused; };
q.disable = function(){
if(this.active) this.active = false;
};
q.isDisabled = function(){ return !this.active; };
q.process = function(){
if(!this.flushed && !this.pending) return;
var self = this,
delay = util.isNumber(this.delay) && !util.isInfinit(this.delay) ? this.delay : 0,
curr = this.queue.shift();
return (this.timer = util.delay(function(){
self.process();
},delay));
};
return q;
}
q.deliver = function(){};
q.flush = function(){};
q.notify = function(){};
q.pause = function(){};
q.resume = function(){};
q.disable = function(){};
q.disabled = function(){};
return function(timeout){
};
})(ToolStack);
//to ensure backward compatibility with calls to MessageAPI instead of MQ
ToolStack.MessageAPI = ToolStack.MQ;