summaryrefslogtreecommitdiffstats
path: root/apps/files_external/js/rollingqueue.js
diff options
context:
space:
mode:
authorJesús Macias <jmacias@solidgear.es>2015-11-24 08:16:14 +0100
committerJesús Macias <jmacias@solidgear.es>2015-11-24 08:16:14 +0100
commit5580b562a36c682c4baea89c7026af5596f714bc (patch)
tree459444019b8a2ba72aed611948c8f6695dbf463a /apps/files_external/js/rollingqueue.js
parent31cfd43e8ad95bec0086409597c35294b7d19df6 (diff)
downloadnextcloud-server-5580b562a36c682c4baea89c7026af5596f714bc.tar.gz
nextcloud-server-5580b562a36c682c4baea89c7026af5596f714bc.zip
Fix code from PR comments
Diffstat (limited to 'apps/files_external/js/rollingqueue.js')
-rw-r--r--apps/files_external/js/rollingqueue.js118
1 files changed, 59 insertions, 59 deletions
diff --git a/apps/files_external/js/rollingqueue.js b/apps/files_external/js/rollingqueue.js
index 0bff974414f..58cb0fb22f0 100644
--- a/apps/files_external/js/rollingqueue.js
+++ b/apps/files_external/js/rollingqueue.js
@@ -59,77 +59,77 @@
* be executed at the same time
*/
var RollingQueue = function (functionList, queueWindow, callback) {
- this.queueWindow = queueWindow || 1;
- this.functionList = functionList;
- this.callback = callback;
- this.counter = 0;
- this.runQueue = function() {
- this.callbackCalled = false;
- this.deferredsList = [];
- if (!$.isArray(this.functionList)) {
- throw "functionList must be an array";
- }
+ this.queueWindow = queueWindow || 1;
+ this.functionList = functionList;
+ this.callback = callback;
+ this.counter = 0;
+ this.runQueue = function() {
+ this.callbackCalled = false;
+ this.deferredsList = [];
+ if (!$.isArray(this.functionList)) {
+ throw "functionList must be an array";
+ }
- for (i = 0; i < this.queueWindow; i++) {
- this.launchNext();
- }
- };
+ for (i = 0; i < this.queueWindow; i++) {
+ this.launchNext();
+ }
+ };
- this.hasNext = function() {
- return (this.counter in this.functionList);
- };
+ this.hasNext = function() {
+ return (this.counter in this.functionList);
+ };
- this.launchNext = function() {
- var currentCounter = this.counter++;
- if (currentCounter in this.functionList) {
- var funcData = this.functionList[currentCounter];
- if ($.isFunction(funcData.funcName)) {
- var defObj = funcData.funcName.apply(funcData.funcName, funcData.funcArgs);
- this.deferredsList.push(defObj);
- if ($.isFunction(funcData.done)) {
- defObj.done(funcData.done);
- }
+ this.launchNext = function() {
+ var currentCounter = this.counter++;
+ if (currentCounter in this.functionList) {
+ var funcData = this.functionList[currentCounter];
+ if ($.isFunction(funcData.funcName)) {
+ var defObj = funcData.funcName.apply(funcData.funcName, funcData.funcArgs);
+ this.deferredsList.push(defObj);
+ if ($.isFunction(funcData.done)) {
+ defObj.done(funcData.done);
+ }
- if ($.isFunction(funcData.fail)) {
- defObj.fail(funcData.fail);
- }
+ if ($.isFunction(funcData.fail)) {
+ defObj.fail(funcData.fail);
+ }
- if ($.isFunction(funcData.always)) {
- defObj.always(funcData.always);
- }
+ if ($.isFunction(funcData.always)) {
+ defObj.always(funcData.always);
+ }
- if (this.hasNext()) {
- var self = this;
- defObj.always(function(){
- _.defer($.proxy(function(){
- self.launchNext();
- }, self));
- });
- } else {
- if (!this.callbackCalled) {
- this.callbackCalled = true;
- if ($.isFunction(this.callback)) {
- $.when.apply($, this.deferredsList)
- .always($.proxy(function(){
- this.callback();
- }, this)
- );
- }
- }
- }
- return defObj;
- }
- }
- return false;
- };
+ if (this.hasNext()) {
+ var self = this;
+ defObj.always(function(){
+ _.defer($.proxy(function(){
+ self.launchNext();
+ }, self));
+ });
+ } else {
+ if (!this.callbackCalled) {
+ this.callbackCalled = true;
+ if ($.isFunction(this.callback)) {
+ $.when.apply($, this.deferredsList)
+ .always($.proxy(function(){
+ this.callback();
+ }, this)
+ );
+ }
+ }
+ }
+ return defObj;
+ }
+ }
+ return false;
+ };
};
if (!OCA.External) {
- OCA.External = {};
+ OCA.External = {};
}
if (!OCA.External.StatusManager) {
- OCA.External.StatusManager = {};
+ OCA.External.StatusManager = {};
}
OCA.External.StatusManager.RollingQueue = RollingQueue;