I have the following code:
//calling AsyncFunction
var coords = LocationSerivice.getLocation();
var localStores;
setTimeout(function(){
//works
console.log(coords);
//calling async function again
localStores = LocalStoresService.getLocalStores(coords[0],coords[1]);
}, 100);
setTimeout(function(){
//doesn't work
console.log(localStores);
}, 100);
What am I trying to do is to first call a Async function that returns my location. Then in order to get the data from that function I am setting timeout. With the data received I am calling second Async function. And again I am setting timeout in order to get the data from my second Async function, so here it fails. If I try to display the data with console.log()
in the timeout block it says undefined
while console.log()
in the first timeout block works.
I have tried also increasing the timeout time but it just doesn't work. Any suggestions how to get over that ?