!function(t){"object"==typeof exports?module.exports=t():"function"==typeof define&&define.amd?define(t):"undefined"!=typeof window?window.when=t():"undefined"!=typeof global?global.when=t():"undefined"!=typeof self&&(self.when=t())}(function(){var t;return function n(t,e,r){function o(u,c){if(!e[u]){if(!t[u]){var f="function"==typeof require&&require;if(!c&&f)return f(u,!0);if(i)return i(u,!0);throw new Error("Cannot find module '"+u+"'")}var a=e[u]={exports:{}};t[u][0].call(a.exports,function(n){var e=t[u][1][n];return o(e?e:n)},a,a.exports,n,t,e,r)}return e[u].exports}for(var i="function"==typeof require&&require,u=0;u1?d.call(arguments,1):[];return function(){return v(t,this,n.concat(d.call(arguments)))}}function u(t,n,e){return p(i,n,e,t)}function c(t,n){return function(){var e=this;return h.all(arguments).then(function(r){var o,i,u=h._defer();return"number"==typeof n.callback&&(o=f(r,n.callback)),"number"==typeof n.errback&&(i=f(r,n.errback)),o>i?(a(r,i,u._handler.reject,u._handler),a(r,o,u._handler.resolve,u._handler)):(a(r,o,u._handler.resolve,u._handler),a(r,i,u._handler.reject,u._handler)),t.apply(e,r),u})}}function f(t,n){return 0>n?t.length+n+2:n}function a(t,n,e,r){"number"==typeof n&&t.splice(n,0,s(e,r))}function s(t,n){return function(){arguments.length>1?t.call(n,d.call(arguments)):t.apply(n,arguments)}}var l=t("./when"),h=l.Promise,p=t("./lib/liftAll"),d=Array.prototype.slice,y=t("./lib/apply"),v=y(h,e);return{lift:i,liftAll:u,apply:n,call:o,promisify:c}})}("function"==typeof t&&t.amd?t:function(t){e.exports=t(n)})},{"./lib/apply":11,"./lib/liftAll":23,"./when":32}],3:[function(n,e,r){!function(t){t(function(){return function(t,n){return t.cancel=function(){try{t.reject(n(t))}catch(e){t.reject(e)}return t.promise},t}})}("function"==typeof t&&t.amd?t:function(t){e.exports=t()})},{}],4:[function(n,e,r){!function(t){t(function(t){var n=t("./when");return function(t,e){return n(e).delay(t)}})}("function"==typeof t&&t.amd?t:function(t){e.exports=t(n)})},{"./when":32}],5:[function(n,e,r){!function(t){t(function(t){function n(t,n){return f(t,this,null==n?[]:a.call(n))}function e(t){var n=arguments.length>1?a.call(arguments,1):[];return function(){return f(t,this,n.concat(a.call(arguments)))}}function r(t,n,r){return c(e,n,r,t)}function o(t){var n=a.call(arguments,1);return function(){var e=this,r=a.call(arguments),o=u.apply(e,[t].concat(r));return i.reduce(n,function(t,n){return n.call(e,t)},o)}}var i=t("./when"),u=i["try"],c=t("./lib/liftAll"),f=t("./lib/apply")(i.Promise),a=Array.prototype.slice;return{lift:e,liftAll:r,call:u,apply:n,compose:o}})}("function"==typeof t&&t.amd?t:function(t){e.exports=t(n)})},{"./lib/apply":11,"./lib/liftAll":23,"./when":32}],6:[function(n,e,r){!function(t){t(function(t){function n(t,n){return function(){var e=o.call(arguments);return r(t()).withThis(this).then(function(t){return r(n.apply(this,e))["finally"](t)})}}function e(t){function n(){e=Math.max(e-1,0),o.length>0&&o.shift()(n)}var e=0,o=[];return function(){return r.promise(function(r){t>e?r(n):o.push(r),e+=1})}}var r=t("./when"),o=Array.prototype.slice;return n.n=e,n})}("function"==typeof t&&t.amd?t:function(t){e.exports=t(n)})},{"./when":32}],7:[function(n,e,r){!function(t){"use strict";t(function(t){function n(t){function n(t,n,e){this[t]=n,0===--f&&e.resolve(i)}for(var e,r=u._defer(),o=u._handler(r),i={},c=Object.keys(t),f=c.length,a=0;a>>0,a=f,s=[],l=0;f>l;++l)if(i=n[l],void 0!==i||l in n){if(o=t._handler(i),o.state()>0){c.become(o),t._visitRemaining(n,l,o);break}o.visit(c,e,r)}else--a;return 0===a&&c.reject(new RangeError("any(): array must not be empty")),u}function o(n,e){function r(t){this.resolved||(s.push(t),0===--p&&(l=null,this.resolve(s)))}function o(t){this.resolved||(l.push(t),0===--i&&(s=null,this.reject(l)))}var i,u,c,f=t._defer(),a=f._handler,s=[],l=[],h=n.length>>>0,p=0;for(c=0;h>c;++c)u=n[c],(void 0!==u||c in n)&&++p;for(e=Math.max(e,0),i=p-e+1,p=Math.min(e,p),e>p?a.reject(new RangeError("some(): array must contain at least "+e+" item(s), but had "+p)):0===p&&a.resolve(s),c=0;h>c;++c)u=n[c],(void 0!==u||c in n)&&t._handler(u).visit(a,r,o,a.notify);return f}function i(n,e){return t._traverse(e,n)}function u(n,e){var r=b.call(n);return t._traverse(e,r).then(function(t){return c(r,t)})}function c(n,e){for(var r=e.length,o=new Array(r),i=0,u=0;r>i;++i)e[i]&&(o[u++]=t._handler(n[i]).value);return o.length=u,o}function f(t){return y(t.map(a))}function a(e){var r=t._handler(e);return 0===r.state()?d(e).then(n.fulfilled,n.rejected):(r._unreport(),n.inspect(r))}function s(t,n){return arguments.length>2?v.call(t,h(n),arguments[2]):v.call(t,h(n))}function l(t,n){return arguments.length>2?m.call(t,h(n),arguments[2]):m.call(t,h(n))}function h(t){return function(n,e,r){return p(t,void 0,[n,e,r])}}var p=e(t),d=t.resolve,y=t.all,v=Array.prototype.reduce,m=Array.prototype.reduceRight,b=Array.prototype.slice;return t.any=r,t.some=o,t.settle=f,t.map=i,t.filter=u,t.reduce=s,t.reduceRight=l,t.prototype.spread=function(t){return this.then(y).then(function(n){return t.apply(this,n)})},t}})}("function"==typeof t&&t.amd?t:function(t){e.exports=t(n)})},{"../apply":11,"../state":25}],13:[function(n,e,r){!function(t){"use strict";t(function(){function t(){throw new TypeError("catch predicate must be a function")}function n(t,n){return e(n)?t instanceof n:n(t)}function e(t){return t===Error||null!=t&&t.prototype instanceof Error}function r(t){return("object"==typeof t||"function"==typeof t)&&null!==t}function o(t){return t}return function(e){function i(t,e){return function(r){return n(r,e)?t.call(this,r):a(r)}}function u(t,n,e,o){var i=t.call(n);return r(i)?c(i,e,o):e(o)}function c(t,n,e){return f(t).then(function(){return n(e)})}var f=e.resolve,a=e.reject,s=e.prototype["catch"];return e.prototype.done=function(t,n){this._handler.visit(this._handler.receiver,t,n)},e.prototype["catch"]=e.prototype.otherwise=function(n){return arguments.length<2?s.call(this,n):"function"!=typeof n?this.ensure(t):s.call(this,i(arguments[1],n))},e.prototype["finally"]=e.prototype.ensure=function(t){return"function"!=typeof t?this:this.then(function(n){return u(t,this,o,n)},function(n){return u(t,this,a,n)})},e.prototype["else"]=e.prototype.orElse=function(t){return this.then(void 0,function(){return t})},e.prototype["yield"]=function(t){return this.then(function(){return t})},e.prototype.tap=function(t){return this.then(t)["yield"](this)},e}})}("function"==typeof t&&t.amd?t:function(t){e.exports=t()})},{}],14:[function(n,e,r){!function(t){"use strict";t(function(){return function(t){return t.prototype.fold=function(n,e){var r=this._beget();return this._handler.fold(function(e,r,o){t._handler(e).fold(function(t,e,r){r.resolve(n.call(this,e,t))},r,this,o)},e,r._handler.receiver,r._handler),r},t}})}("function"==typeof t&&t.amd?t:function(t){e.exports=t()})},{}],15:[function(n,e,r){!function(t){"use strict";t(function(t){var n=t("../state").inspect;return function(t){return t.prototype.inspect=function(){return n(t._handler(this))},t}})}("function"==typeof t&&t.amd?t:function(t){e.exports=t(n)})},{"../state":25}],16:[function(n,e,r){!function(t){"use strict";t(function(){return function(t){function n(t,n,r,o){return e(function(n){return[n,t(n)]},n,r,o)}function e(t,n,o,i){function u(i,u){return r(o(i)).then(function(){return e(t,n,o,u)})}return r(i).then(function(e){return r(n(e)).then(function(n){return n?e:r(t(e)).spread(u)})})}var r=t.resolve;return t.iterate=n,t.unfold=e,t}})}("function"==typeof t&&t.amd?t:function(t){e.exports=t()})},{}],17:[function(n,e,r){!function(t){"use strict";t(function(){return function(t){return t.prototype.progress=function(t){return this.then(void 0,void 0,t)},t}})}("function"==typeof t&&t.amd?t:function(t){e.exports=t()})},{}],18:[function(n,e,r){!function(t){"use strict";t(function(t){function n(t,n,r,o){return e.setTimer(function(){t(r,o,n)},n)}var e=t("../env"),r=t("../TimeoutError");return function(t){function o(t,e,r){n(i,t,e,r)}function i(t,n){n.resolve(t)}function u(t,n,e){var o="undefined"==typeof t?new r("timed out after "+e+"ms"):t;n.reject(o)}return t.prototype.delay=function(t){var n=this._beget();return this._handler.fold(o,t,void 0,n._handler),n},t.prototype.timeout=function(t,r){var o=this._beget(),i=o._handler,c=n(u,t,r,o._handler);return this._handler.visit(i,function(t){e.clearTimer(c),this.resolve(t)},function(t){e.clearTimer(c),this.reject(t)},i.notify),o},t}})}("function"==typeof t&&t.amd?t:function(t){e.exports=t(n)})},{"../TimeoutError":10,"../env":21}],19:[function(n,e,r){!function(t){"use strict";t(function(t){function n(t){throw t}function e(){}var r=t("../env").setTimer,o=t("../format");return function(t){function i(t){t.handled||(p.push(t),s("Potentially unhandled rejection ["+t.id+"] "+o.formatError(t.value)))}function u(t){var n=p.indexOf(t);n>=0&&(p.splice(n,1),l("Handled previous rejection ["+t.id+"] "+o.formatObject(t.value)))}function c(t,n){h.push(t,n),null===d&&(d=r(f,0))}function f(){for(d=null;h.length>0;)h.shift()(h.shift())}var a,s=e,l=e;"undefined"!=typeof console&&(a=console,s="undefined"!=typeof a.error?function(t){a.error(t)}:function(t){a.log(t)},l="undefined"!=typeof a.info?function(t){a.info(t)}:function(t){a.log(t)}),t.onPotentiallyUnhandledRejection=function(t){c(i,t)},t.onPotentiallyUnhandledRejectionHandled=function(t){c(u,t)},t.onFatalRejection=function(t){c(n,t.value)};var h=[],p=[],d=null;return t}})}("function"==typeof t&&t.amd?t:function(t){e.exports=t(n)})},{"../env":21,"../format":22}],20:[function(n,e,r){!function(t){"use strict";t(function(){return function(t){return t.prototype["with"]=t.prototype.withThis=function(t){var n=this._beget(),e=n._handler;return e.receiver=t,this._handler.chain(e,t),n},t}})}("function"==typeof t&&t.amd?t:function(t){e.exports=t()})},{}],21:[function(n,e,r){!function(t){"use strict";t(function(t){function n(){return"undefined"!=typeof process&&"[object process]"===Object.prototype.toString.call(process)}function e(){return"function"==typeof MutationObserver&&MutationObserver||"function"==typeof WebKitMutationObserver&&WebKitMutationObserver}function r(t){function n(){var t=e;e=void 0,t()}var e,r=document.createTextNode(""),o=new t(n);o.observe(r,{characterData:!0});var i=0;return function(t){e=t,r.data=i^=1}}var o,i="undefined"!=typeof setTimeout&&setTimeout,u=function(t,n){return setTimeout(t,n)},c=function(t){return clearTimeout(t)},f=function(t){return i(t,0)};if(n())f=function(t){return process.nextTick(t)};else if(o=e())f=r(o);else if(!i){var a=t,s=a("vertx");u=function(t,n){return s.setTimer(n,t)},c=s.cancelTimer,f=s.runOnLoop||s.runOnContext}return{setTimer:u,clearTimer:c,asap:f}})}("function"==typeof t&&t.amd?t:function(t){e.exports=t(n)})},{}],22:[function(n,e,r){!function(t){"use strict";t(function(){function t(t){var e="object"==typeof t&&null!==t&&(t.stack||t.message)?t.stack||t.message:n(t);return t instanceof Error?e:e+" (WARNING: non-Error used)"}function n(t){var n=String(t);return"[object Object]"===n&&"undefined"!=typeof JSON&&(n=e(t,n)),n}function e(t,n){try{return JSON.stringify(t)}catch(e){return n}}return{formatError:t,formatObject:n,tryStringify:e}})}("function"==typeof t&&t.amd?t:function(t){e.exports=t()})},{}],23:[function(n,e,r){!function(t){"use strict";t(function(){function t(t,n,e){return t[e]=n,t}function n(t){return"function"==typeof t?t.bind():Object.create(t)}return function(e,r,o,i){return"undefined"==typeof r&&(r=t),Object.keys(i).reduce(function(t,n){var o=i[n];return"function"==typeof o?r(t,e(o),n):t},"undefined"==typeof o?n(i):o)}})}("function"==typeof t&&t.amd?t:function(t){e.exports=t()})},{}],24:[function(n,e,r){!function(t){"use strict";t(function(){return function(t){function n(t,n){this._handler=t===g?n:e(t)}function e(t){function n(t){o.resolve(t)}function e(t){o.reject(t)}function r(t){o.notify(t)}var o=new w;try{t(n,e,r)}catch(i){e(i)}return o}function r(t){return L(t)?t:new n(g,new j(v(t)))}function o(t){return new n(g,new j(new A(t)))}function i(){return $}function u(){return new n(g,new w)}function c(t,n){var e=new w(t.receiver,t.join().context);return new n(g,e)}function f(t){return s(K,null,t)}function a(t,n){return s(N,t,n)}function s(t,e,r){function o(n,o,u){u.resolved||l(r,i,n,t(e,o,n),u)}function i(t,n,e){s[t]=n,0===--a&&e.become(new k(s))}for(var u,c="function"==typeof e?o:i,f=new w,a=r.length>>>0,s=new Array(a),h=0;h0?n(e,i.value,o):(o.become(i),h(t,e+1,i))}else n(e,r,o)}function h(t,n,e){for(var r=n;re&&t._unreport()}}function d(t){return"object"!=typeof t||null===t?o(new TypeError("non-iterable passed to race()")):0===t.length?i():1===t.length?r(t[0]):y(t)}function y(t){var e,r,o,i=new w;for(e=0;e0||"function"!=typeof n&&0>o)return new this.constructor(g,r);var i=this._beget(),u=i._handler;return r.chain(u,r.receiver,t,n,e),i},n.prototype["catch"]=function(t){return this.then(void 0,t)},n.prototype._beget=function(){return c(this._handler,this.constructor)},n.all=f,n.race=d,n._traverse=a,n._visitRemaining=h,g.prototype.when=g.prototype.become=g.prototype.notify=g.prototype.fail=g.prototype._unreport=g.prototype._report=D,g.prototype._state=0,g.prototype.state=function(){return this._state},g.prototype.join=function(){for(var t=this;void 0!==t.handler;)t=t.handler;return t},g.prototype.chain=function(t,n,e,r,o){this.when({resolver:t,receiver:n,fulfilled:e,rejected:r,progress:o})},g.prototype.visit=function(t,n,e,r){this.chain(X,t,n,e,r)},g.prototype.fold=function(t,n,e,r){this.when(new Q(t,n,e,r))},J(g,_),_.prototype.become=function(t){t.fail()};var X=new _;J(g,w),w.prototype._state=0,w.prototype.resolve=function(t){this.become(v(t))},w.prototype.reject=function(t){this.resolved||this.become(new A(t))},w.prototype.join=function(){if(!this.resolved)return this;for(var t=this;void 0!==t.handler;)if(t=t.handler,t===this)return this.handler=R();return t},w.prototype.run=function(){var t=this.consumers,n=this.handler;this.handler=this.handler.join(),this.consumers=void 0;for(var e=0;e0?e(r.value):n(r.value)}return{pending:t,fulfilled:e,rejected:n,inspect:r}})}("function"==typeof t&&t.amd?t:function(t){e.exports=t()})},{}],26:[function(n,e,r){!function(t){t(function(t){function n(t,n){return p(t,this,n||[])}function e(t,n,e,r){var o=u(r);try{switch(e.length){case 2:t.call(n,e[0],e[1],o);break;case 1:t.call(n,e[0],o);break;case 0:t.call(n,o);break;default:e.push(o),t.apply(n,e)}}catch(i){r.reject(i)}}function r(t){return p(t,this,h.call(arguments,1))}function o(t){var n=arguments.length>1?h.call(arguments,1):[];return function(){var e,r=n.length,o=arguments.length,i=new Array(o+r);for(e=0;r>e;++e)i[e]=n[e];for(e=0;o>e;++e)i[e+r]=arguments[e];return p(t,this,i)}}function i(t,n,e){return s(o,n,e,t)}function u(t){return function(n,e){n?t.reject(n):arguments.length>2?t.resolve(h.call(arguments,1)):t.resolve(e)}}function c(t,n){function e(t){r(null,t)}function r(t,e){l(function(){n(t,e)},0)}return t=a(t),n&&t.then(e,r),t}function f(t){return function(n){return c(n,t)}}var a=t("./when"),s=t("./lib/liftAll"),l=t("./lib/env").setTimer,h=Array.prototype.slice,p=t("./lib/apply")(a.Promise,e);return{lift:o,liftAll:i,apply:n,call:r,createCallback:u,bindCallback:c,liftCallback:f}})}("function"==typeof t&&t.amd?t:function(t){e.exports=t(n)})},{"./lib/apply":11,"./lib/env":21,"./lib/liftAll":23,"./when":32}],27:[function(n,e,r){!function(t){t(function(t){var n=t("./when"),e=n.Promise.all,r=Array.prototype.slice;return function(t){return e(r.call(arguments,1)).then(function(e){return n.map(t,function(t){return t.apply(void 0,e)})})}})}("function"==typeof t&&t.amd?t:function(t){e.exports=t(n)})},{"./when":32}],28:[function(n,e,r){!function(t){t(function(t){var n=t("./when"),e=n.Promise.all,r=Array.prototype.slice;return function(t){var o=function(t,n){return o=function(t,n){return n(t)},n.apply(null,t)};return e(r.call(arguments,1)).then(function(e){return n.reduce(t,function(t,n){return o(t,n)},e)})}})}("function"==typeof t&&t.amd?t:function(t){e.exports=t(n)})},{"./when":32}],29:[function(n,e,r){!function(t){"use strict";t(function(t){var n=t("./when"),e=n["try"],r=t("./cancelable");return function(t,o,i,u){function c(t){s.resolve(t)}function f(t){e(o).then(a,h),void 0!==t&&s.notify(t)}function a(){l||n(t(),function(t){n(i(t),function(n){return n?c(t):f(t)},function(){f(t)})},h)}var s,l,h;return l=!1,s=r(n.defer(),function(){l=!0}),h=s.reject,i=i||function(){return!1},"function"!=typeof o&&(o=function(t){return function(){return n().delay(t)}}(o)),u?f():a(),s.promise=Object.create(s.promise),s.promise.cancel=s.cancel,s.promise}})}("function"==typeof t&&t.amd?t:function(t){e.exports=t(n)})},{"./cancelable":3,"./when":32}],30:[function(n,e,r){!function(t){t(function(t){var n=t("./when"),e=n.Promise.all,r=Array.prototype.slice;return function(t){function o(t){return i.push(t),i}var i=[];return e(r.call(arguments,1)).then(function(e){return n.reduce(t,function(t,r){return n(r.apply(void 0,e),o)},i)})}})}("function"==typeof t&&t.amd?t:function(t){e.exports=t(n)})},{"./when":32}],31:[function(n,e,r){!function(t){t(function(t){var n=t("./when");return function(t,e){return n(e).timeout(t)}})}("function"==typeof t&&t.amd?t:function(t){e.exports=t(n)})},{"./when":32}],32:[function(n,e,r){!function(t){"use strict";t(function(t){function n(t,n,e,r){var o=x.resolve(t);return arguments.length<2?o:o.then(n,e,r)}function e(t){return new x(t)}function r(t){return function(){for(var n=0,e=arguments.length,r=new Array(e);e>n;++n)r[n]=arguments[n];return k(t,this,r)}}function o(t){for(var n=0,e=arguments.length-1,r=new Array(e);e>n;++n)r[n]=arguments[n+1];return k(t,this,r)}function i(){return new u}function u(){function t(t){r._handler.resolve(t)}function n(t){r._handler.reject(t)}function e(t){r._handler.notify(t)}var r=x._defer();this.promise=r,this.resolve=t,this.reject=n,this.notify=e,this.resolver={resolve:t,reject:n,notify:e}}function c(t){return t&&"function"==typeof t.then}function f(){return x.all(arguments)}function a(t){return n(t,x.all)}function s(t){return n(t,x.settle)}function l(t,e){return n(t,function(t){return x.map(t,e)})}function h(t,e){return n(t,function(t){return x.filter(t,e)})}var p=t("./lib/decorators/timed"),d=t("./lib/decorators/array"),y=t("./lib/decorators/flow"),v=t("./lib/decorators/fold"),m=t("./lib/decorators/inspect"),b=t("./lib/decorators/iterate"),g=t("./lib/decorators/progress"),_=t("./lib/decorators/with"),w=t("./lib/decorators/unhandledRejection"),j=t("./lib/TimeoutError"),x=[d,y,v,b,g,m,_,p,w].reduce(function(t,n){return n(t)},t("./lib/Promise")),k=t("./lib/apply")(x);return n.promise=e,n.resolve=x.resolve,n.reject=x.reject,n.lift=r,n["try"]=o,n.attempt=o,n.iterate=x.iterate,n.unfold=x.unfold,n.join=f,n.all=a,n.settle=s,n.any=r(x.any),n.some=r(x.some),n.race=r(x.race),n.map=l,n.filter=h,n.reduce=r(x.reduce),n.reduceRight=r(x.reduceRight),n.isPromiseLike=c,n.Promise=x,n.defer=i,n.TimeoutError=j,n})}("function"==typeof t&&t.amd?t:function(t){e.exports=t(n)})},{"./lib/Promise":8,"./lib/TimeoutError":10,"./lib/apply":11,"./lib/decorators/array":12,"./lib/decorators/flow":13,"./lib/decorators/fold":14,"./lib/decorators/inspect":15,"./lib/decorators/iterate":16,"./lib/decorators/progress":17,"./lib/decorators/timed":18,"./lib/decorators/unhandledRejection":19,"./lib/decorators/with":20}]},{},[1])(1)}); //# sourceMappingURL=when.min.js.map