Script to Wait for javascript function to end

I always tend to have this problem.
Say I try to do something like that


slide_image();
get_current_image();

get_current_image will return the wrong result, because the animation for the slide_image() has not ended.
Is there a wait function or something?
setTimeout is not that ideal too since multiple calls stacks up the queue.

That can depend on the code library that you are using. Which particular image slider are you using?

Actually I wrote my own, based on the tutorial here: http://jonraasch.com/blog/a-simple-jquery-slideshow
I was using jQuery’s animate function and could throw my ending script in the complete method.

But I keep hitting this problem and wonder how I can over come it by manually injecting a waiting script.
That is, instead of writing my ending script in the complete method, write it after I call the animate function.
Its easier to read that way too.

What is normally done is to pass a callback function to the slider, so that when your animation comes to an end, the callback (if any) can then be called.