How to wait until function ends? In manner function execute in event ( by clicking element )?

How to wait until function ends? In manner function execute in event ( by clicking element )?
0

#1

what is best way to wait until function ends in event, like if we set jQuery event function for clicking on some element and we click speedy twice in row, and function didn’t success to execute self to the end?
I asking this to be sure for my game, that AI pass all function he had and then can continue game?
I use bool working to know if he working something, please take a look at the code, working is at the start of $(".field").click function