// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://@sbaseurl@/jsapi/jsapi/esri/copyright.txt and http://www.arcgis.com/apps/webappbuilder/copyright.txt for details.

//>>built
define(["dojo/_base/declare","dojo/_base/lang","dojo/Deferred"],function(e,f,c){var d=e(null,{_realRequest:null,_buffer:null,constructor:function(a){this._buffer={};this._realRequest=a?a:function(){return new c}},getRequest:function(a){this._buffer[a]||(this._buffer[a]=new d.RequestProxy(this._realRequest,a));return this._buffer[a]},request:function(a){var b=Array.prototype.slice.apply(arguments);b.splice(0,1);var g=this.getRequest(a);return g.request.apply(g,b)},setResponse:function(a,b){this.getRequest(a).setResponse(b)},
isResolved:function(a){return this.getRequest(a).isResolved()}});d.RequestProxy=e(null,{_key:null,_deferred:null,_realRequest:null,constructor:function(a,b){this._realRequest=a;this._key=b},request:function(){this._deferred||(this._deferred=new c,this._realRequest.apply(null,arguments).then(f.hitch(this,function(a){this._deferred.resolve(a)}),f.hitch(this,function(a){a&&console.warn(a.message||a);a=this._deferred;this._deferred=null;a.resolve(null)})));return this._deferred},fakeRequest:function(){this._deferred||
(this._deferred=new c);return this._deferred},setResponse:function(a,b){this._deferred||(this._deferred=new c);null===a||void 0===a?(this._deferred.resolve(null),b&&(this._deferred=null)):this._deferred.resolve(a)},isResolved:function(){return this._deferred&&this._deferred.isResolved()}});return d});