When I try to get something from local sqlite or from ajax request I can’t have some value returned, I need to run a callback.
I have some pretty big function that gets and processes some data but I need to put it in the loop and keep it till it’s finished . I can’t accomplish it like that ’cause function is finished before internal callbacks run. I could make a callback run that function again, but wouldn’t it eat the memory? Or it wouldn’t because parent function is finished and internal variables and objects are destroyed?
Sorry for my english.
I if understand correctly you have a process that passes a callback to a function that you want to repeat in a loop which makes multiple outstanding callbacks.
The solution to this is to keep a count of the callbacks and decrement it when each one is called. Once the counter reaches zero do your final processing.
Be careful to start the counter at one and decrement it once all the callbacks have been passed off to ensure that the counter doesn’t prematurely reach zero.