I have a function outside my control which triggers a series of callbacks to a function I control, and upon receiving an end message, I want to trigger some followup actions.
function myFunction(data)
{
if(!!data)
{
global.finished = true;
}
else
{
global.loadedData += data;
}
}
function getInfoAboutData()
{
EXTERNAL.getData(myFunction); // returns immediately, then async calls myFunction until done, then calls with null
// PROBLEM -> Wait on data to be loaded, or return something I can wait on
return data.substring(...)
}
I'm open to returning a promise I can wait on in the calling function, or if there's a way to wait on global.finished === true.
Edit: To clarify, I'm looking for advice on how I wrap the loadedData flag in a promise here, since getData does not return a promise, and does not wait on completion to return.