-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathFCallQueueProcessor.js
More file actions
41 lines (35 loc) · 978 Bytes
/
FCallQueueProcessor.js
File metadata and controls
41 lines (35 loc) · 978 Bytes
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
'use strict'
function FCallQueueProcessor(func, thisArg, delay) {
this.dispatch_delay_ms =
typeof delay !== 'undefined' ? delay : 100;
this.fcall_q = [];
this.check_active = false;
this.func = func;
this.func_context = thisArg;
};
//check_probe_q
FCallQueueProcessor.prototype.poll_q = function() {
var _this = this;
if(_this.fcall_q.length > 0) {
// each 'fcall' is a list of parameters to be supplied to this.func
var fcall = _this.fcall_q.shift();
_this.check_active = true;
// TRACKING show the current CRN being tested
// console.log(fcall[0]);
_this.func.apply(_this.func_context, fcall);
setTimeout(function() {
_this.poll_q();
}, _this.dispatch_delay_ms);
} else {
_this.check_active = false;
}
}
FCallQueueProcessor.prototype.alert_q_to_poll = function() {
if (!this.check_active) {
this.poll_q();
}
};
FCallQueueProcessor.prototype.empty = function() {
return !this.fcall_q.length;
}
module.exports = FCallQueueProcessor;