javascript - run after the callback is finished -


i need run function after displaypredictionsuggestions callback retrieves , stores result in global variable place.

as understand callback runs asynchronously. can't sure callback finished when invoke console.log( json.stringfy( place ) );

how make sure program continues after callback finished (without nesting)?

predictionservice = new google.maps.places.autocompleteservice(); predictionservice.getplacepredictions({      input: '1 street, city' },      displaypredictionsuggestions );  displaypredictionsuggestions = function(predictions, status) {          place = predictions[0]['place_id'];     }  console.log( json.stringfy( place ) ); 

you can avoid nesting callbacks using promises.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -