Using an async flow and returning to a variable in the original called function
I understand how to use functions as well as async functions with binding and calling binding. But I have been looking for a solution for the following for a long time.
To figure out why this is not a duplicate: I know how asynchronous calls work. I also understand why the variable is not being updated directly (due to the time difference between the start and end of the call). My question is simplified: is it possible to go back to the original function and populate the variable?
Consider the following pseudo JavaScript code:
var returnedData = loadDataThroughAjax(url);
function loadDataThroughAjax(url)
{
//here fires an xhrrequest using the specific url
return xhr.readystatefunction = function()
{
if (this.reaystate == 4)
{
return this.responseText;
}
}
}
I would like the responsetext
call to be loaded into var returnedData
in one thread. I looked at some code jquery
and it looks like you could pull this, or is what I am asking about is not possible for an asynchronous call?
source to share
No one has answered this question yet
See similar questions:
or similar: