Files
galaxy/static/scripts/utils/ajax-queue.js
T

2 lines
1.6 KiB
JavaScript

define([],function(){function a(a){var b=this;return b.deferred=jQuery.Deferred(),b.queue=[],b.responses=[],b.numToProcess=0,b.running=!1,b.init(a||[]),b.start(),b}function b(b){var c=this;return c.names={},a.call(this,b),c}return a.prototype.init=function(a){var b=this;a.forEach(function(a){b.add(a)})},a.prototype.add=function(a){var b=this,c=this.queue.length;this.numToProcess+=1,this.queue.push(function(){var d=c,e=a();e.done(function(a){b.deferred.notify({curr:d,total:b.numToProcess,response:a})}),e.always(function(a){b.responses.push(a),b.queue.length?b.queue.shift()():b.stop()})})},a.prototype.start=function(){this.queue.length&&(this.running=!0,this.queue.shift()())},a.prototype.stop=function(a,b){return this.running=!1,this.queue=[],a?this.deferred.reject(b):this.deferred.resolve(this.responses),this.numToProcess=0,this.deferred=jQuery.Deferred(),this},a.prototype.done=function(a){return this.deferred.done(a)},a.prototype.fail=function(a){return this.deferred.fail(a)},a.prototype.always=function(a){return this.deferred.always(a)},a.prototype.progress=function(a){return this.deferred.progress(a)},a.create=function(b){return new a(b).deferred},b.prototype=new a,b.prototype.constructor=b,b.prototype.add=function(b){if(!b.hasOwnProperty("name")||!b.hasOwnProperty("fn"))throw new Error('NamedAjaxQueue.add requires an object with both "name" and "fn": '+JSON.stringify(b));this.names.hasOwnProperty(b.name)||(this.names[b.name]=!0,a.prototype.add.call(this,b.fn))},b.prototype.clear=function(){this.names={}},b.create=function(a){return new b(a).deferred},{AjaxQueue:a,NamedAjaxQueue:b}});
//# sourceMappingURL=../../maps/utils/ajax-queue.js.map