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

One way to deal with asynchronous work like this is to use a callback function, eg: As per @Janaka Pushpakumara’s suggestion, you can now use arrow functions to achieve the same thing. For example: firstFunction(() => console.log(‘huzzah, I\’m done!’)) Update: I answered this quite some time ago, and really want to update it. While callbacks are … Read more

Lua Program Delay

The os.clock function returns the number of seconds of CPU time for the program. So the sleep function of yours waits for n seconds, if you need to delay 2 minutes, just call: Note that there are some better solutions to implement sleep functions other than busy waiting, see Sleep Function for detail.

JavaScript sleep/wait before continuing [duplicate]

JS does not have a sleep function, it has setTimeout() or setInterval() functions. If you can move the code that you need to run after the pause into the setTimeout() callback, you can do something like this: see example here : http://jsfiddle.net/9LZQp/ This won’t halt the execution of your script, but due to the fact that setTimeout() is an asynchronous function, this code will … Read more