What is the best practice to call a function which loads the db and tell it to wait for it to execute before my function continues? I think my load is taking longer than expected an my function is processing without waiting for completion of the data loading.
I had a similar issue. I suggest making it asynchronous, i.e. set a flag and have a callback mechanism to fire when the db has finished loading. How do we know when its done? maybe start by passing the number of records and check when all of them have loaded.
Doing it with a timer will never be accurate based on size of table, network conditions etc.