I am creating a custom Dojo module that returns some data from a server. The problem is that I have an AJAX function within the module definition and I cannot return the outer function from the inner function when the request completes. If I simply return the outer function, it will return before I get a response from the server. I don't want to make the request synchronous (even though it works) because then I lose the benefit of the asynchronous module loading. I want other modules to be loaded at the same time as this one but I want it to wait for completion before returning.
What is the correct approach here? Should I be trying to return the outer function from the inner one? I've looked into this and can't seem to find anything.
Help is greatly appreciated!
define(["dojo/request","config/config"], function(Request, Config){
var imageTableId;
var req_opt = {handleAs:'json'};
Request.get(Config.RESTURL + "?f=json", req_opt).then(function(data){
for (var i = 0; i < data.tables.length; i++){
if (data.tables[i].name == "NotableTreeImageMap"){
imageTableId = data.tables[i].id;
return imageTableId;
}
}
},
function(error){
console.log(error);
});
//return imageTableId;
});