//>>built
define("dojo/_base/Deferred","./kernel,../Deferred,../promise/Promise,../errors/CancelError,../has,./lang,../when".split(","),function(c,f,t,u,q,g,v){var o=function(){},w=Object.freeze||function(){},n=c.Deferred=function(c){function l(a){if(h)throw Error("This deferred has already been resolved");i=a;h=!0;r()}function r(){for(var a;!a&&e;){var b=e;e=e.next;if(a=b.progress==o)h=!1;var d=j?b.error:b.resolved;q("config-useDeferredInstrumentation")&&j&&f.instrumentRejected&&f.instrumentRejected(i,!!d);
if(d)try{var k=d(i);k&&"function"===typeof k.then?k.then(g.hitch(b.deferred,"resolve"),g.hitch(b.deferred,"reject"),g.hitch(b.deferred,"progress")):(d=a&&void 0===k,a&&!d&&(j=k instanceof Error),b.deferred[d&&j?"reject":"resolve"](d?i:k))}catch(c){b.deferred.reject(c)}else j?b.deferred.reject(i):b.deferred.resolve(i)}}var i,h,j,p,e,m=this.promise=new t;this.resolve=this.callback=function(a){this.fired=0;this.results=[a,null];l(a)};this.reject=this.errback=function(a){j=!0;this.fired=1;q("config-useDeferredInstrumentation")&&
f.instrumentRejected&&f.instrumentRejected(a,!!e);l(a);this.results=[null,a]};this.progress=function(a){for(var b=e;b;){var d=b.progress;d&&d(a);b=b.next}};this.addCallbacks=function(a,b){this.then(a,b,o);return this};m.then=this.then=function(a,b,d){var c=d==o?this:new n(m.cancel),a={resolved:a,error:b,progress:d,deferred:c};e?p=p.next=a:e=p=a;h&&r();return c.promise};var s=this;m.cancel=this.cancel=function(){if(!h){var a=c&&c(s);if(!h)a instanceof Error||(a=new u(a)),a.log=!1,s.reject(a)}};w(m)};
g.extend(n,{addCallback:function(f){return this.addCallbacks(g.hitch.apply(c,arguments))},addErrback:function(f){return this.addCallbacks(null,g.hitch.apply(c,arguments))},addBoth:function(f){var l=g.hitch.apply(c,arguments);return this.addCallbacks(l,l)},fired:-1});n.when=c.when=v;return n});