-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaq.js
111 lines (95 loc) · 2.94 KB
/
aq.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
* ApplicationQuees
* @author skitsanos
* @date 11/3/15
* @version 1.0.0
*/
var ApplicationQueues = {
AbstractCommand: function (lbl)
{
return {
label: lbl != undefined ? lbl : '',
execute: function ()
{
},
toString: function ()
{
return 'queues.AbstractCommand ' + this.label;
},
commandComplete: function ()
{
this.queue.currentCommandExecuted();
},
commandFail: function ()
{
this.queue.currentCommandExecuted();
}
}
},
Queue: function ()
{
var commandList = new HashMap();
var currentCommand = null;
var currentCommandIndex = 0;
return {
toString: function ()
{
return 'queues.CommandQueue ' + this.label;
},
count: function ()
{
return commandList.count();
},
currentCommandExecuted: function ()
{
this.removeCommand([currentCommand]);
this.execute();
},
queueExecuted: function ()
{
},
addCommand: function (commands)
{
for (var i = 0; i < commands.length; i++)
{
var cmd = commands[i];
cmd.queue = this;
commandList.set(currentCommandIndex, cmd);
currentCommandIndex++;
}
},
removeCommand: function (commands)
{
//console.log(commandList.count() + ' command are still in queue');
for (var i = 0; i < commands.length; i++)
{
console.log(commandList.search(commands[i]));
if (commandList.search(commands[i]) != null)
{
//console.log('removing {' + commandList.keys()[i] + '}' + commands[i].label + ' from the queue')
commandList.remove(commandList.keys()[i]);
//console.log(commandList.count() + ' command are still in queue');
}
else
{
//console.log('not found');
}
}
},
execute: function ()
{
if (commandList.count() < 1)
{
console.log('all done');
this.queueExecuted();
}
else
{
//console.log('[queue.execute:] ' + commandList.count() + ' command are in queue');
currentCommand = commandList.get(commandList.keys()[0]);
currentCommand.execute();
}
}
}
}
};