-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpromisque.min.js
1 lines (1 loc) · 906 Bytes
/
promisque.min.js
1
function Promisque(){return{stack:[],interrupt:!1,mode:null,push:function(){var t=arguments;return t.length>0&&"function"==typeof t[0]&&this.stack.push({callback:t[0],arguments:[].slice.call(t,1)}),this},next:function(){return this.stack.length>0?this.stack.splice(0,1)[0]:null},run:function(t,n){if(void 0!=n&&(this.mode=n),this.stack.length>0&&0==this.interrupt){var i=this.stack.splice(0,t);if("pipe"==this.mode)for(var e=0;e<t;e++)this.createPipe(i[e],e);else $.when.apply(null,i.map(function(t){return t.callback.apply(null,t.arguments)})).then($.proxy(function(){this.run(t,this.mode)},this))}return this},createPipe:function(t,n){return t.callback.apply(null,t.arguments).then($.proxy(function(){var t=this.next();if(t)return this.createPipe(t,n)},this))},pause:function(){return this.interrupt=!0,this},stop:function(){return this.pause().clear(),this},clear:function(){return this.stack=[],this}}}