Proper way to wait for one function to finish before continuing?

I have two JS functions. One calls the other. Within the calling function, I’d like to call the other, wait for that function to finish, then continue on. So, for example/pseudo code: function firstFunction(){ for(i=0;i<x;i++){ // do something } }; function secondFunction(){ firstFunction() // now wait for firstFunction to finish… // do something else }; … Read more

JavaScript sleep/wait before continuing [duplicate]

This question already has answers here: What is the JavaScript version of sleep()? (88 answers) Closed 8 years ago. I have a JavaScript code that I need to add a sleep/wait function to. The code I am running is already in a function, eg: function myFunction(time) { alert(‘time starts now’); //code to make the program … Read more

How to call a method after a delay in Android

I want to be able to call the following method after a specified delay. In objective c there was something like: [self performSelector:@selector(DoSomething) withObject:nil afterDelay:5]; Is there an equivalent of this method in android with java? For example I need to be able to call a method after 5 seconds. public void DoSomething() { //do … Read more