/*
YUI 3.13.0 (build 508226d)
Copyright 2013 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
*/

YUI.add("promise",function(e,t){function n(e){if(!(this instanceof n))return new n(e);var t=new n.Resolver(this);this._resolver=t,e.call(this,function(e){t.fulfill(e)},function(e){t.reject(e)})}function r(e){this._callbacks=[],this._errbacks=[],this.promise=e,this._status="pending"}e.mix(n.prototype,{then:function(e,t){return this._resolver.then(e,t)},getStatus:function(){return this._resolver.getStatus()}}),n.isPromise=function(e){return!!e&&typeof e.then=="function"},e.Promise=n,e.mix(r.prototype,{fulfill:function(e){this._status==="pending"&&(this._result=e),this._status!=="rejected"&&(this._notify(this._callbacks,this._result),this._callbacks=[],this._errbacks=null,this._status="fulfilled")},reject:function(e){this._status==="pending"&&(this._result=e),this._status!=="fulfilled"&&(this._notify(this._errbacks,this._result),this._callbacks=null,this._errbacks=[],this._status="rejected")},then:function(e,t){var n=this.promise,r,i,s=new n.constructor(function(e,t){r=e,i=t}),o=this._callbacks||[],u=this._errbacks||[];return o.push(typeof e=="function"?this._wrap(r,i,e):r),u.push(typeof t=="function"?this._wrap(r,i,t):i),this._status==="fulfilled"?this.fulfill(this._result):this._status==="rejected"&&this.reject(this._result),s},_wrap:function(e,t,r){return function(i){var s;try{s=r(i)}catch(o){return t(o)}n.isPromise(s)?s.then(e,t):e(s)}},getStatus:function(){return this._status},_notify:function(t,n){t.length&&e.soon(function(){var e,r;for(e=0,r=t.length;e<r;++e)t[e](n)})}},!0),e.Promise.Resolver=r,e.when=function(t,n,r){var i;return e.Promise.isPromise(t)||(i=t,t=new e.Promise(function(e){e(i)})),n||r?t.then(n,r):t};var i=[].slice;e.batch=function(){var t=i.call(arguments),n=t.length,r=0,s=t.length,o=[];return new e.Promise(function(i,u){function f(e){return function(t){o[e]=t,n--,!n&&a.getStatus()!=="rejected"&&i(o)}}var a=this;if(s<1)return i(o);for(;r<s;r++)e.when(t[r],f(r),u)})}},"3.13.0",{requires:["timers"]});
