"use strict";
_kangoLoader.add("kango/invoke_async", function(require, exports, module) {
function InvokeAsyncModule(n,e,r,o){function t(n){var r=arguments[arguments.length-1],o=r.isCallbackInvoke?s:l,t=Array.prototype.slice.call(arguments,1,arguments.length-1),a=null;r.isNotifyInvoke||(a=c(),i[a]=r),e(o,{id:a,method:n,params:t})}var a="KangoInvokeAsyncModule_result",l="KangoInvokeAsyncModule_invoke",s="KangoInvokeAsyncModule_invokeCallback",i={},u=0,c=function(){return(Math.random()+u++).toString()},d=function(n){return"undefined"!=typeof n.call&&"undefined"!=typeof n.apply},f=function(n,e){var t={id:n.id,result:null,error:null};try{t.result=r(n.method,n.params)}catch(l){var s=l.message;l.stack&&(s+="\nStack:\n"+l.stack),t.error=s,o("Error during async call method "+n.method+". Details: "+s,l)}null!=n.id&&e.dispatchMessage(a,t)},y=function(n,e){var t={id:n.id,result:null,error:null};try{n.params.push(function(r){t.result=r,null!=n.id&&e.dispatchMessage(a,t)}),r(n.method,n.params)}catch(l){t.error=l.toString(),null!=n.id?e.dispatchMessage(a,t):o("Error during async call method "+n.method+". Details: "+t.error,l)}},v=function(n,e){if("undefined"!=typeof n.id&&"undefined"!=typeof i[n.id]){var r=i[n.id];try{null==n.error&&d(r.onSuccess)?r.onSuccess(n.result):d(r.onError)&&r.onError(n.error)}finally{delete i[n.id]}}};n("message",function(n){var e={};e[l]=f,e[s]=y,e[a]=v;var r=n.data;for(var o in e)if(e.hasOwnProperty(o)&&o==n.name){e[o](r,n.source);break}});var h=function(n,e){e=Array.prototype.slice.call(e,0);var r=e[e.length-1],a={onSuccess:function(){},onError:function(n){o("Error during async call method "+e[0]+". Details: "+n)},isCallbackInvoke:n,isNotifyInvoke:!1};null!=r&&d(r)?(a.onSuccess=function(n){r(n)},e[e.length-1]=a):(a.isNotifyInvoke=!0,e.push(a)),t.apply(this,e)};this.invokeAsync=function(n){h(!1,arguments)},this.invokeAsyncCallback=function(n){h(!0,arguments)}}"undefined"!=typeof module&&(module.exports=InvokeAsyncModule);
});