/*
	Copyright (c) 2004-2016, The JS Foundation All Rights Reserved.
	Available via Academic Free License >= 2.1 OR the modified BSD license.
	see: http://dojotoolkit.org/license for details
*/

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