-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
46 lines (42 loc) · 1.14 KB
/
index.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
// Copyright 2014 Technical Machine, Inc.
//
// Licensed under the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>.
// This file may not be copied, modified, or distributed
// except according to those terms.
function queue() {
// Create an empty array of commands
var queue = [];
// We're inactive to begin with
queue.active = false;
// Method for adding command chain to the queue
queue.place = function (command) {
// Push the command onto the command array
queue.push(command);
// If we're currently inactive, start processing
if (!queue.active) queue.next();
};
// Method for calling the next command chain in the array
queue.next = function () {
// If this is the end of the queue
if (!queue.length) {
// We're no longer active
queue.active = false;
// Stop execution
return;
}
// Grab the next command
var command = queue.shift();
// We're active
queue.active = true;
// Call the command
command();
};
//Clearing queue
queue.clear = function(){
queue.length = 0;
queue.active = false;
};
return queue;
}
module.exports = queue;