1
|
!function(){function n(){}function t(n){var t=!1;return function(){if(t)throw new Error("Callback was already called.");t=!0,n.apply(this,arguments)}}function e(n){var t=!1;return function(){t||(t=!0,n.apply(this,arguments))}}function r(n){return P(n)||"number"==typeof n.length&&n.length>=0&&n.length%1===0}function u(n,t){return r(n)?i(n,t):f(n,t)}function i(n,t){for(var e=-1,r=n.length;++e<r;)t(n[e],e,n)}function o(n,t){for(var e=-1,r=n.length,u=Array(r);++e<r;)u[e]=t(n[e],e,n);return u}function c(n){return o(Array(n),function(n,t){return t})}function a(n,t,e){return i(n,function(n,r,u){e=t(e,n,r,u)}),e}function f(n,t){i(U(n),function(e){t(n[e],e)})}function l(n){var t,e,u=-1;return r(n)?(t=n.length,function(){return u++,t>u?u:null}):(e=U(n),t=e.length,function(){return u++,t>u?e[u]:null})}function s(n,t){t=t||0;var e=-1,r=n.length;t&&(r-=t,r=0>r?0:r);for(var u=Array(r);++e<r;)u[e]=n[e+t];return u}function p(n){return function(t,e,r){return n(t,r)}}function m(r){return function(u,i,o){o=e(o||n),u=u||[];var c=l(u);if(0>=r)return o(null);var a=!1,f=0,s=!1;!function p(){if(a&&0>=f)return o(null);for(;r>f&&!s;){var n=c();if(null===n)return a=!0,void(0>=f&&o(null));f+=1,i(u[n],n,t(function(n){f-=1,n?(o(n),s=!0):p()}))}}()}}function h(n){return function(t,e,r){return n(L.eachOf,t,e,r)}}function g(n,t){return function(e,r,u){return t(m(n),e,r,u)}}function d(n){return function(t,e,r){return n(L.eachOfSeries,t,e,r)}}function v(t,r,u,i){i=e(i||n);var o=[];t(r,function(n,t,e){u(n,function(n,r){o[t]=r,e(n)})},function(n){i(n,o)})}function y(n){return g(n,v)}function k(n,t,e,r){var u=[];t=o(t,function(n,t){return{index:t,value:n}}),n(t,function(n,t,r){e(n.value,function(t){t&&u.push(n),r()})},function(){r(o(u.sort(function(n,t){return n.index-t.index}),function(n){return n.value}))})}function b(n,t,e,r){k(n,t,function(n,t){e(n,function(n){t(!n)})},r)}function w(t,e,r,u){t(e,function(t,e,i){r(t,function(e){e?(u(t),u=n):i()})},function(){u()})}function O(t,e,u){u=u||n;var i=r(e)?[]:{};t(e,function(n,t,e){n(function(n){var r=s(arguments,1);r.length<=1&&(r=r[0]),i[t]=r,e(n)})},function(n){u(n,i)})}function x(n,t,e,r){var u=[];n(t,function(n,t,r){e(n,function(n,t){u=u.concat(t||[]),r(n)})},function(n){r(n,u)})}function S(e,r,u){function c(t,e,r,u){if(null!=u&&"function"!=typeof u)throw new Error("task callback must be a function");return t.started=!0,P(e)||(e=[e]),0===e.length&&t.idle()?L.setImmediate(function(){t.drain()}):(i(e,function(e){var i={data:e,callback:u||n};r?t.tasks.unshift(i):t.tasks.push(i),t.tasks.length===t.concurrency&&t.saturated()}),void L.setImmediate(t.process))}function a(n,t){return function(){f-=1;var e=arguments;i(t,function(n){n.callback.apply(n,e)}),n.tasks.length+f===0&&n.drain(),n.process()}}if(null==r)r=1;else if(0===r)throw new Error("Concurrency must not be zero");var f=0,l={tasks:[],concurrency:r,payload:u,saturated:n,empty:n,drain:n,started:!1,paused:!1,push:function(n,t){c(l,n,!1,t)},kill:function(){l.drain=n,l.tasks=[]},unshift:function(n,t){c(l,n,!0,t)},process:function(){if(!l.paused&&f<l.concurrency&&l.tasks.length)for(;f<l.concurrency&&l.tasks.length;){var n=l.payload?l.tasks.splice(0,l.payload):l.tasks.splice(0,l.tasks.length),r=o(n,function(n){return n.data});0===l.tasks.length&&l.empty(),f+=1;var u=t(a(l,n));e(r,u)}},length:function(){return l.tasks.length},running:function(){return f},idle:function(){return l.tasks.length+f===0},pause:function(){l.paused=!0},resume:function(){if(l.paused!==!1){l.paused=!1;for(var n=Math.min(l.concurrency,l.tasks.length),t=1;n>=t;t++)L.setImmediate(l.process)}}};return l}function E(n){return function(t){var e=s(arguments,1);t.apply(null,e.concat([function(t){var e=s(arguments,1);"undefined"!=typeof console&&(t?console.error&&console.error(t):console[n]&&i(e,function(t){console[n](t)}))}]))}}function I(n){return function(t,e,r){n(c(t),e,r)}}function T(n,t){function e(){var e=this,r=s(arguments),u=r.pop();return n(t,function(n,t,u){n.apply(e,r.concat([u]))},u)}if(arguments.length>2){var r=s(arguments,2);return e.apply(this,r)}return e}function j(n){return function(){var t=s(arguments),e=t.pop();t.push(function(){var n=arguments;r?L.setImmediate(function(){e.apply(null,n)}):e.apply(null,n)});var r=!0;n.apply(this,t),r=!1}}var A,L={},z="object"==typeof self&&self.self===self&&self||"object"==typeof global&&global.global===global&&global||this;null!=z&&(A=z.async),L.noConflict=function(){return z.async=A,L};var q,C=Object.prototype.toString,P=Array.isArray||function(n){return"[object Array]"===C.call(n)},U=Object.keys||function(n){var t=[];for(var e in n)n.hasOwnProperty(e)&&t.push(e);return t};"function"==typeof setImmediate&&(q=setImmediate),"undefined"!=typeof process&&process.nextTick?(L.nextTick=process.nextTick,q?L.setImmediate=function(n){q(n)}:L.setImmediate=L.nextTick):q?(L.nextTick=function(n){q(n)},L.setImmediate=L.nextTick):(L.nextTick=function(n){setTimeout(n,0)},L.setImmediate=L.nextTick),L.forEach=L.each=function(n,t,e){return L.eachOf(n,p(t),e)},L.forEachSeries=L.eachSeries=function(n,t,e){return L.eachOfSeries(n,p(t),e)},L.forEachLimit=L.eachLimit=function(n,t,e,r){return m(t)(n,p(e),r)},L.forEachOf=L.eachOf=function(i,o,c){function a(n){n?c(n):(l+=1,l>=f&&c(null))}c=e(c||n),i=i||[];var f=r(i)?i.length:U(i).length,l=0;return f?void u(i,function(n,e){o(i[e],e,t(a))}):c(null)},L.forEachOfSeries=L.eachOfSeries=function(r,u,i){function o(){var n=!0;return null===a?i(null):(u(r[a],a,t(function(t){if(t)i(t);else{if(a=c(),null===a)return i(null);n?L.nextTick(o):o()}})),void(n=!1))}i=e(i||n),r=r||[];var c=l(r),a=c();o()},L.forEachOfLimit=L.eachOfLimit=function(n,t,e,r){m(t)(n,e,r)},L.map=h(v),L.mapSeries=d(v),L.mapLimit=function(n,t,e,r){return y(t)(n,e,r)},L.inject=L.foldl=L.reduce=function(n,t,e,r){L.eachOfSeries(n,function(n,r,u){e(t,n,function(n,e){t=e,u(n)})},function(n){r(n||null,t)})},L.foldr=L.reduceRight=function(n,t,e,r){var u=o(n,function(n){return n}).reverse();L.reduce(u,t,e,r)},L.select=L.filter=h(k),L.selectSeries=L.filterSeries=d(k),L.reject=h(b),L.rejectSeries=d(b),L.detect=h(w),L.detectSeries=d(w),L.any=L.some=function(t,e,r){L.eachOf(t,function(t,u,i){e(t,function(t){t&&(r(!0),r=n),i()})},function(){r(!1)})},L.all=L.every=function(t,e,r){L.eachOf(t,function(t,u,i){e(t,function(t){t||(r(!1),r=n),i()})},function(){r(!0)})},L.sortBy=function(n,t,e){function r(n,t){var e=n.criteria,r=t.criteria;return r>e?-1:e>r?1:0}L.map(n,function(n,e){t(n,function(t,r){t?e(t):e(null,{value:n,criteria:r})})},function(n,t){return n?e(n):void e(null,o(t.sort(r),function(n){return n.value}))})},L.auto=function(t,r){function u(n){m.unshift(n)}function o(n){for(var t=0;t<m.length;t+=1)if(m[t]===n)return void m.splice(t,1)}function c(){l--,i(m.slice(0),function(n){n()})}r=e(r||n);var f=U(t),l=f.length;if(!l)return r(null);var p={},m=[];u(function(){l||r(null,p)}),i(f,function(n){function e(t){var e=s(arguments,1);if(e.length<=1&&(e=e[0]),t){var u={};i(U(p),function(n){u[n]=p[n]}),u[n]=e,r(t,u)}else p[n]=e,L.setImmediate(c)}function f(){return a(g,function(n,t){return n&&p.hasOwnProperty(t)},!0)&&!p.hasOwnProperty(n)}function l(){f()&&(o(l),h[h.length-1](e,p))}for(var m,h=P(t[n])?t[n]:[t[n]],g=h.slice(0,Math.abs(h.length-1))||[],d=g.length;d--;){if(!(m=t[g[d]]))throw new Error("Has inexistant dependency");if(P(m)&&~m.indexOf(n))throw new Error("Has cyclic dependencies")}f()?h[h.length-1](e,p):u(l)})},L.retry=function(){function n(n,t){if("number"==typeof t)n.times=parseInt(t,10)||e;else{if("object"!=typeof t)throw new Error("Unsupported argument type for 'times': "+typeof t);n.times=parseInt(t.times,10)||e,n.interval=parseInt(t.interval,10)||r}}function t(n,t){function e(n,e){return function(r){n(function(n,t){r(!n||e,{err:n,result:t})},t)}}function r(n){return function(t){setTimeout(function(){t(null)},n)}}for(;i.times;){var o=!(i.times-=1);u.push(e(i.task,o)),!o&&i.interval>0&&u.push(r(i.interval))}L.series(u,function(t,e){e=e[e.length-1],(n||i.callback)(e.err,e.result)})}var e=5,r=0,u=[],i={times:e,interval:r};switch(arguments.length){case 1:i.task=arguments[0];break;case 2:"number"==typeof arguments[0]||"object"==typeof arguments[0]?(n(i,arguments[0]),i.task=arguments[1]):(i.task=arguments[0],i.callback=arguments[1]);break;case 3:n(i,arguments[0]),i.task=arguments[1],i.callback=arguments[2];break;default:throw new Error("Invalid arguments - must be either (task), (task, callback), (times, task) or (times, task, callback)")}return i.callback?t():t},L.waterfall=function(t,r){function u(n){return function(t){if(t)r.apply(null,arguments);else{var e=s(arguments,1),i=n.next();i?e.push(u(i)):e.push(r),j(n).apply(null,e)}}}if(r=e(r||n),!P(t)){var i=new Error("First argument to waterfall must be an array of functions");return r(i)}return t.length?void u(L.iterator(t))():r()},L.parallel=function(n,t){O(L.eachOf,n,t)},L.parallelLimit=function(n,t,e){O(m(t),n,e)},L.series=function(t,e){e=e||n;var u=r(t)?[]:{};L.eachOfSeries(t,function(n,t,e){n(function(n){var r=s(arguments,1);r.length<=1&&(r=r[0]),u[t]=r,e(n)})},function(n){e(n,u)})},L.iterator=function(n){function t(e){function r(){return n.length&&n[e].apply(null,arguments),r.next()}return r.next=function(){return e<n.length-1?t(e+1):null},r}return t(0)},L.apply=function(n){var t=s(arguments,1);return function(){return n.apply(null,t.concat(s(arguments)))}},L.concat=h(x),L.concatSeries=d(x),L.whilst=function(t,e,r){r=r||n,t()?e(function(n){return n?r(n):void L.whilst(t,e,r)}):r(null)},L.doWhilst=function(t,e,r){r=r||n,t(function(n){if(n)return r(n);var u=s(arguments,1);e.apply(null,u)?L.doWhilst(t,e,r):r(null)})},L.until=function(t,e,r){r=r||n,t()?r(null):e(function(n){return n?r(n):void L.until(t,e,r)})},L.doUntil=function(t,e,r){r=r||n,t(function(n){if(n)return r(n);var u=s(arguments,1);e.apply(null,u)?r(null):L.doUntil(t,e,r)})},L.during=function(t,e,r){r=r||n,t(function(n,u){return n?r(n):void(u?e(function(n){return n?r(n):void L.during(t,e,r)}):r(null))})},L.doDuring=function(t,e,r){r=r||n,t(function(n){if(n)return r(n);var u=s(arguments,1);u.push(function(n,u){return n?r(n):void(u?L.doDuring(t,e,r):r(null))}),e.apply(null,u)})},L.queue=function(n,t){var e=S(function(t,e){n(t[0],e)},t,1);return e},L.priorityQueue=function(t,e){function r(n,t){return n.priority-t.priority}function u(n,t,e){for(var r=-1,u=n.length-1;u>r;){var i=r+(u-r+1>>>1);e(t,n[i])>=0?r=i:u=i-1}return r}function o(t,e,o,c){if(null!=c&&"function"!=typeof c)throw new Error("task callback must be a function");return t.started=!0,P(e)||(e=[e]),0===e.length?L.setImmediate(function(){t.drain()}):void i(e,function(e){var i={data:e,priority:o,callback:"function"==typeof c?c:n};t.tasks.splice(u(t.tasks,i,r)+1,0,i),t.tasks.length===t.concurrency&&t.saturated(),L.setImmediate(t.process)})}var c=L.queue(t,e);return c.push=function(n,t,e){o(c,n,t,e)},delete c.unshift,c},L.cargo=function(n,t){return S(n,1,t)},L.log=E("log"),L.dir=E("dir"),L.memoize=function(n,t){function e(){var e=s(arguments),i=e.pop(),o=t.apply(null,e);o in r?L.nextTick(function(){i.apply(null,r[o])}):o in u?u[o].push(i):(u[o]=[i],n.apply(null,e.concat([function(){r[o]=s(arguments);var n=u[o];delete u[o];for(var t=0,e=n.length;e>t;t++)n[t].apply(null,arguments)}])))}var r={},u={};return t=t||function(n){return n},e.memo=r,e.unmemoized=n,e},L.unmemoize=function(n){return function(){return(n.unmemoized||n).apply(null,arguments)}},L.times=I(L.map),L.timesSeries=I(L.mapSeries),L.timesLimit=function(n,t,e,r){return L.mapLimit(c(n),t,e,r)},L.seq=function(){var t=arguments;return function(){var e=this,r=s(arguments),u=r.slice(-1)[0];"function"==typeof u?r.pop():u=n,L.reduce(t,r,function(n,t,r){t.apply(e,n.concat([function(){var n=arguments[0],t=s(arguments,1);r(n,t)}]))},function(n,t){u.apply(e,[n].concat(t))})}},L.compose=function(){return L.seq.apply(null,Array.prototype.reverse.call(arguments))},L.applyEach=function(){var n=s(arguments);return T.apply(null,[L.eachOf].concat(n))},L.applyEachSeries=function(){var n=s(arguments);return T.apply(null,[L.eachOfSeries].concat(n))},L.forever=function(e,r){function u(n){return n?i(n):void o(u)}var i=t(r||n),o=j(e);u()},L.ensureAsync=j,L.constant=function(){var n=[null].concat(s(arguments));return function(t){return t.apply(this,n)}},L.wrapSync=L.asyncify=function(n){return function(){var t,e=s(arguments),r=e.pop();try{t=n.apply(this,e)}catch(u){return r(u)}r(null,t)}},"undefined"!=typeof module&&module.exports?module.exports=L:"undefined"!=typeof define&&define.amd?define([],function(){return L}):z.async=L}();
|