-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueuecue.js
More file actions
124 lines (103 loc) · 2.95 KB
/
Copy pathqueuecue.js
File metadata and controls
124 lines (103 loc) · 2.95 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
(function() {
var _backupQC = typeof QC === 'undefined' ? undefined : QC;
window.QC = {};
QC.parallel = function() {
var _queue = [],
_outstanding = 0,
_finishedCallback,
_running = false,
_self = this,
_commObj;
_commObj = {
insert: function(func, params, scope) {
params = params || [];
scope = scope || window;
_queue.unshift({func: func, scope: scope, params: params});
_outstanding++;
_self.run();
return _commObj;
},
return: function() {
if (--_outstanding === 0 && typeof _finishedCallback == 'function') {
_running = false;
this.push = null;
_finishedCallback();
}
}
};
this.q = _queue;
this.push = function(func, params, scope) {
params = params || [];
scope = scope || window;
_outstanding++;
_queue.push({func: func, scope: scope, params: params});
if (_running === true) {
this.run();
}
return this;
};
this.run = function(cb) {
var item, params;
if (typeof cb !== 'undefined' && typeof cb.return == 'function') {
_finishedCallback = cb.return;
} else if (typeof cb === 'function') {
_finishedCallback = cb;
}
while (item = _queue.shift()) {
if (typeof item.triggered !== 'undefined') continue;
params = Array.prototype.slice.call(item.params); // copy params so we can push the callback
params.push(_commObj); // add the callback for the async function to call when it's done
item.func.apply(item.scope, params);
item.triggered = true;
}
_running = true;
};
return this;
};
QC.serial = function() {
var _queue = [],
_finishedCallback,
_self = this,
_commObj;
_commObj = {
insert: function(func, params, scope) {
params = params || [];
scope = scope || window;
_queue.unshift({func: func, scope: scope, params: params});
return _commObj;
},
return: function() {
_self.run();
}
};
this.q = _queue;
this.push = function(func, params, scope) {
params = params || [];
scope = scope || window;
_queue.push({func: func, scope: scope, params: params});
return this;
};
this.run = function(cb) {
var item, params;
if (typeof cb !== 'undefined' && typeof cb.return == 'function') {
_finishedCallback = cb.return;
} else if (typeof cb === 'function') {
_finishedCallback = cb;
}
if (item = _queue.shift()) {
params = Array.prototype.slice.call(item.params); // copy params so we can push the callback
params.push(_commObj); // add the callback for the async function to call when it's done
item.func.apply(item.scope, params);
item.triggered = true;
} else if (typeof _finishedCallback == 'function') {
_finishedCallback();
}
};
return this;
}
QC.noConflict = function() {
var newObj = QC;
QC = _backupQC;
return newObj;
};
})();