I am working on a Mozilla extension and have a problem when I make n calls for an asynchronous function, this function is not in my control and makes a callback at the end. In this callback, I need to perform a special action if this is the nth and last callback. I canβt figure out how to determine if the callback is final, I thought about setting up the counter and decreasing it every time, but because of the nested loop, I donβt know in advance how many asynchronous calls will be made (without preliminary development, which would be inefficient ) Any ideas on an elegant approach to this?
function dataCallBack(mHdr, mimeData)
{
}
function getData() {
var secSize = secList.length;
for (var i = 0; i < secSize; i++) {
if (secList[i].shares.length >= secList[i].t) {
var hdrCount = secList[i].hdrArray.length;
for(var j = 0; j < hdrCount; j++)
{
mozillaFunction(secList[i].hdrArray[j], this, dataCallBack);
}
}
}
}
Thank.
source
share