Free javascript Hosting


promisequeueplus-min.js

Uploaded on Nov 18 2021 12:42 by droessler89

/*!
* promise-queue-plus v1.2.2
* Homepage https://github.com/cnwhy/promise-queue-plus
* License BSD-2-Clause
*/
!function o(i,u,s){function f(r,t){if(!u[r]){if(!i[r]){var e="function"==typeof require&&require;if(!t&&e)return e(r,!0);if(c)return c(r,!0);throw new Error("Cannot find module '"+r+"'")}var n=u[r]={exports:{}};i[r][0].call(n.exports,function(t){var e=i[r][1][t];return f(e||t)},n,n.exports,o,i,u,s)}return u[r].exports}for(var c="function"==typeof require&&require,t=0;t<s.length;t++)f(s[t]);return f}({1:[function(t,e,r){!function(t,e){if("function"==typeof define&&(define.amd||define.cmd))define([],e);else{if("undefined"==typeof window&&"undefined"==typeof self)throw new Error('Loading the "'+t+'" module failed!');("undefined"!=typeof window?window:self)[t]=e()}}("PromiseQueuePlus",function(){return t("../src/queue")(t("easy-promise/setTimeout"))})},{"../src/queue":6,"easy-promise/setTimeout":2}],2:[function(t,e,r){e.exports=t("./src")(function(t){setTimeout(t,0)})},{"./src":3}],3:[function(t,e,r){e.exports=function(u){var i=function(){};function s(t){return t instanceof f}function f(t){var e=this;this.status=-1;var r=!(this._events=[]);function n(t){c.call(e,1,t)}function o(t){c.call(e,0,t)}if(this.resolve=function(t){if(!r){if(r=!0,e===t)return o(new TypeError("The promise and its value refer to the same object"));!function e(r,t){if(s(t))t.then(r.resolve,r.reject);else if(!t||"function"!=typeof t&&"object"!=typeof t)r.resolve(t);else{var n,o=!1;try{"function"==typeof(n=t.then)?n.call(t,function(t){o||(o=!0,e(r,t))},function(t){o||(o=!0,r.reject(t))}):r.resolve(t)}catch(t){o||(o=!0,r.reject(t))}}}({resolve:n,reject:o},t)}},this.reject=function(t){r||(r=!0,o(t))},t!==i&&"function"==typeof t)try{t(this.resolve,this.reject)}catch(t){this.reject(t)}}function c(t,e){~this.status||((this.status=t)?this.value=e:this.reason=e,function(){if(!~this.status)return;for(var t=this,e=t._events,r=t.status?t.value:t.reason,n=t.status?0:1,o=0;o<e.length;o++)i=e[o],s=u=void 0,u=i[n],s=i[2],a(u,r,s,t.status);var i,u,s;e=[]}.call(this))}function a(e,r,t,n){var o=t.resolve,i=t.reject;"function"==typeof e?u(function(){var t;try{t=e(r)}catch(t){return void i(t)}o(t)}):n?o(r):i(r)}return f.defer=function(){var t=new f(i);return{promise:t,resolve:t.resolve,reject:t.reject}},f.resolve=function(r){return s(r)?r:new f(function(t,e){t(r)})},f.reject=function(r){return new f(function(t,e){e(r)})},f.all=function(s){if("[object Array]"!==Object.prototype.toString.call(s))throw new TypeError("The argument is not an array!");return new f(function(r,t){var n=[],o=0,i=s.length,e=function(e){return function(t){n[e]=t,++o==i&&r(n)}};if(i<=0)return r([]);for(var u=0;u<i;u++)f.resolve(s[u]).then(e(u),t)})},f.prototype.toString=function(){return"[object Promise]"},f.prototype.then=function(t,e){var r=this.status,n=f.defer(),o=n.promise;return~r?r&&"function"==typeof t?a(t,this.value,o,r):r||"function"!=typeof e?r?n.resolve(this.value):n.reject(this.reason):a(e,this.reason,o,r):this._events.push([t,e,o]),o},f.prototype.catch=function(t){return this.then(null,t)},f.prototype.finally=function(e){return"function"!=typeof e?this:this.then(function(t){return f.resolve(e()).then(function(){return t})},function(t){return f.resolve(e()).then(function(){throw t})})},f}},{}],4:[function(t,e,r){"use strict";var n=t("./utils"),c=n.isArray,l=n.isEmpty,p=n.isFunction,h=n.isPlainObject,v=n.arg2arr;e.exports=function(t,e,n){var a,o;function r(t){if(c(n)){for(var e=!1,r=0;r<n.length;r++)if(n[r]==t){e=!0;break}if(!e)return!1}return!o||!p(a[t])}if((a=e?(o=!0,e):t).Promise||t==e||(a.Promise=t),p(t)&&p(t.prototype.then))a.defer=function(){var r,n;return{promise:new t(function(t,e){r=t,n=e}),resolve:r,reject:n}};else if(p(t.defer))a.defer=function(){return t.defer()};else{if(!p(t.deferred))throw new TypeError("此类不支持扩展!");a.defer=function(){return t.deferred()}}function i(s,f){return l(f)||(f=0<+f?+f:0),function(r){var n,o=a.defer(),i=0,t=function(e){var t=r[e];a.resolve(t).then(function(t){void 0!==f?n.push(t):n[e]=t,(0==--i||!s&&f&&n.length>=f)&&o.resolve(n)},function(t){l(f)?o.reject(t):0==--i&&o.resolve(n)}),i++};if(c(r)){n=[],0==r.length&&o.resolve(n);for(var e=0;e<r.length;e++)t(e)}else if(s&&h(r)){var u=0;for(var e in n={},r)t(e),u++;0==u&&o.resolve(n)}else o.reject(new TypeError("参数错误"));return o.promise}}function u(t){for(var e,r=a.defer(),n=0;n<t.length;n++)e=t[n],a.resolve(e).then(function(t){r.resolve(t)},function(t){r.reject(t)});return r.promise}function s(r){return function(t,e){if(t)return r.reject(t);r.resolve(e)}}function f(t){var e=this===a?null:this,r=a.defer(),n=v(arguments,1);return n.push(s(r)),t.apply(e,n),r.promise}return r("delay")&&(a.delay=function(t,e){var r=a.defer();return setTimeout(function(){r.resolve(e)},t),r.promise}),r("resolve")&&(a.resolve=function(t){var e=a.defer();return e.resolve(t),e.promise}),r("reject")&&(a.reject=function(t){var e=a.defer();return e.reject(t),e.promise}),r("all")&&(a.all=i()),r("allMap")&&(a.allMap=i(!0)),r("some")&&(a.some=function(t,e){return i(!1,e=0<=+e?+e:0)(t)}),r("map")&&(a.map=function(r,n,t){var o=a.defer(),i=[],u=t?+t.concurrency:0;if(0==u||u!=u){for(var e in r)i.push(n(r[e],e,r));return a.all(i).then(o.resolve,o.reject),o.promise}var s=0,f=function(){var t=[];for(var e in r)t.push(e);return t}();function c(){if(s<f.length){var t=f[s],e=a.resolve(n(r[t],t,r)).then(function(t){return c(),t},o.reject);i.push(e),u--,s++}else a.all(i).then(o.resolve,o.reject)}for(;c(),0<u&&s<f.length;);return o.promise}),r("race")&&(a.race=u),r("any")&&(a.any=u),r("nfcall")&&(a.nfcall=f),r("nfapply")&&(a.nfapply=function(t,e){var r=this===a?null:this,n=a.defer();if(!c(e))throw TypeError('"args" is not Array');return e.push(s(n)),t.apply(r,e),n.promise}),a.denodeify=function(t){var e=this===a?null:this;return function(){return f.apply(e,[].concat([t],v(arguments)))}},a}},{"./utils":5}],5:[function(t,e,r){"use strict";r.isPlainObject=function(t){return null!==t&&"object"==typeof t&&!t.nodeType&&t!==t.window&&!(t.constructor&&!Object.prototype.hasOwnProperty.call(t.constructor.prototype,"isPrototypeOf"))},r.isArray=function(t){return"[object Array]"==Object.prototype.toString.call(t)},r.isFunction=function(t){return"function"==typeof t},r.isEmpty=function(t){return null==t},r.arg2arr=function(t,e,r){return Array.prototype.slice.call(t,e,r)}},{}],6:[function(t,e,r){var A=t("./utils");e.exports=function t(e){var a;r(e);var i=function(t){console.error(t)},m=function(t){return A.runFn2Promise(a,t)};function r(t){a=u.Q=u.Promise=A.extendPromise(t)}function u(t,e){if(!(this instanceof u))return new u(t,e);var a=this,r={queueStart:null,queueEnd:null,workAdd:null,workResolve:null,workReject:null,workFinally:null,retry:0,retryIsJump:!1,timeout:0,autoRun:!1},l=[],p=A.getPositiveInt(t),h=0,v=!1,y=0;if(this._options=r,this.onError=i,A.isObject(e))for(var n in e)r.hasOwnProperty(n)&&(r[n]=e[n]);function o(){if(h<p&&!y&&0<l.length){var t,e=l.shift(),r=0,n=+j("timeout",e,a),o=j("retry",e,a),i=j("retryIsJump",e,a),u=e._options.self,s=function(){if(t&&clearTimeout(t),t=0,r++)return!0;h--},f=function(){g(e,a,"workFinally",a,a,e)},c=function(t){s()||(o>e._errNo++?a._addItem(e,i,!0,!1):(e.defer.reject(t),g(e,a,"workReject",a,t,a,e)),f())};return 0!=h||v||(v=!0,w.call(a,"queueStart",a,a)),m(function(){return e.fn.apply(u||null,e.regs)}).then(function(t){s()||(e.defer.resolve(t),g(e,a,"workResolve",a,t,a,e),f())},c).then(function(){0<l.length?d():0==h&&v&&(v=!1,w.call(a,"queueEnd",a,a))}),h+=1,void(0<n&&(t=setTimeout(function(){c("timeout")},n)))}return!0}function d(){for(;!o(););}this.getMax=function(){return p},this.setMax=function(t){p=A.getPositiveInt(t),!y&&h&&a.start()},this.getLength=function(){return l.length},this.getRunCount=function(){return h},this.isStart=function(){return!!v},this._addItem=function(t,e,r,n){if(!(t instanceof s))throw new TypeError('"unit" is not QueueUnit');e?l.unshift(t):l.push(t),n||function(t){w.call(this,"workAdd",this,t,this)}.call(a,t),r||a._options.autoRun?a.start():v&&d()},this.start=function(){y=0,d()},this.stop=function(){y=1},this.clear=function(t){for(;l.length;)l.shift().defer.reject(t)}}function s(t,e,r){var n={workResolve:!0,workReject:!0,workFinally:!0,queueEventTrigger:!0,regs:[],self:null},o=["workResolve","workReject","workFinally","queueEventTrigger","retry","retryIsJump","timeout","self"],i=1;if(!A.isFunction(t))throw new TypeError("Queues only support function, '"+t+"' is not function");function u(t){for(var e=0;e<o.length;e++)if(t===o[e])return!0;return!1}this.fn=t,this._errNo=0,this.defer=a.defer(),A.isArray(e)&&(this.regs=e,i++),this._options=n;var s=arguments[i];if(A.isObject(s))for(var f in s)u(f)&&(n[f]=s[f])}function j(t,e,r){return t in e._options?e._options[t]:r._options[t]}function w(t,e){var r=this._options[t],n=A.arg2arr(arguments,2);if(!A.isFunction(r))return!!r;try{return r.apply(e,n)}catch(t){(function(t){A.isFunction(this.onError)&&this.onError.call(this,t)}).call(e,t)}}function g(t,e){var r=t._options.queueEventTrigger,n=A.arg2arr(arguments,2);!1!==w.apply(t,n)&&r&&w.apply(e,n)}function n(t,e,r){return new s(t,e,r)}function o(t,e){var r,n=this.queue,o=this.map,i=this.each,u=function(t,e,r){var n,o=2;return A.isObject(r)&&(n=r,o++),{con:n,start:arguments[o],jump:arguments[++o]}}.apply(null,arguments);return r=function(r,n,o,i){var t=A.isArray(r),u=t?[]:{};function e(t){var e=i?A.toArray([r[t]],[t],[r]):A.toArray(r[t]);u[t]=[n,e,o]}if(t)for(var s=0;s<r.length;s++)e(s);else for(var f in r)e(f);return u}(t,e,u.con,i),o?n.addProps(r,u.start,u.jump):n.addArray(r,u.start,u.jump)}return u.prototype={option:function(t){if(1==arguments.length)return this._options[t];1<arguments.length&&(this._options[t]=arguments[1])},push:function(){var t=n.apply(this,arguments);return this._addItem(t,!1),t.defer.promise},unshift:function(){var t=n.apply(this,arguments);return this._addItem(t,!0),t.defer.promise},go:function(){var t=n.apply(this,arguments);return this._addItem(t,!1,!0),t.defer.promise},jump:function(){var t=n.apply(this,arguments);return this._addItem(t,!0,!0),t.defer.promise},add:function(e,t){var r,n,o,i=this,u=1;if(!A.isFunction(e))throw new TypeError("Queues only support function, '"+e+"' is not function");return r=[function(){var t=a.defer();return e(t.resolve,t.reject),t.promise}],A.isObject(t)&&(r.push(t),u++),n=!!arguments[u],o=arguments[u+1]?i.unshift.apply(i,r):i.push.apply(i,r),n&&i.start(),o},addArray:function(t,e,r){for(var n,o,i,u=[],s=this,f=0;f<t.length;f++)n=f,o=A.toArray(t[n]),i=r?s.unshift.apply(s,o):s.push.apply(s,o),u.push(i);var c=a.defer();return a.all(u).then(function(t){c.resolve(t)},function(t){c.reject(t)}),e&&s.start(),c.promise},addProps:function(t,e,r){var n,o,i,u={},s=this;for(var f in t)n=f,o=A.toArray(t[n]),i=r?s.unshift.apply(s,o):s.push.apply(s,o),u[n]=i;var c=a.defer();return a.allMap(u).then(function(t){c.resolve(t)},function(t){c.reject(t)}),e&&s.start(),c.promise},addLikeArray:function(t,e,r){return o.apply({queue:this},arguments)},addLikeProps:function(t,e,r){return o.apply({queue:this,map:!0},arguments)},addLikeArrayEach:function(t,e,r){return o.apply({queue:this,each:!0},arguments)},addLikePropsEach:function(t,e,r){return o.apply({queue:this,each:!0,map:!0},arguments)}},u.use=r,u.createUse=t,u}},{"./utils":7}],7:[function(t,e,r){var n=t("extend-promise/src/extendClass");r.isArray=function(t){return"[object Array]"==Object.prototype.toString.call(t)},r.isFunction=function(t){return"function"==typeof t},r.isObject=function(t){return"object"==typeof t&&null!==t},r.arg2arr=function(t,e,r){return Array.prototype.slice.call(t,e,r)},r.toArray=function(){return Array.prototype.concat.apply([],arguments)},r.getPositiveInt=function(t){var e=+t>>0;if(1<=e)return e;throw new Error('The "max" value is invalid')},r.extendPromise=function(t){return n(t,{})},r.runFn2Promise=function(e,t){try{return e.resolve(t())}catch(t){return e.reject(t)}}},{"extend-promise/src/extendClass":4}]},{},[1]);

Back to list