-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue.js
44 lines (37 loc) · 955 Bytes
/
queue.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
function Queue() {
this.dataStore = [];
this.offer = offer;
this.poll = poll;
this.execNext = execNext;
this.debug = false;
this.startDebug = startDebug;
function offer(element) {
if(this.debug){
console.log('Offered a Queued Function.');
}
if(typeof element === 'function') {
this.dataStore.push(element);
} else {
console.log('You must offer a function.');
}
}
function poll() {
if(this.debug){
console.log('Polled a Queued Function.');
}
return this.dataStore.shift();
}
function execNext() {
var nextfunc = this.poll();
if(nextfunc !== undefined) {
if(this.debug){
console.log('Run a Queued Function.');
}
nextfunc();
}
}
function startDebug(){
this.debug = true;
}
}
var queue = new Queue();