the simpliest way for you would be to break original function with a wait operation in the middle into 2 functions.
I mean if you have this a function looking like that:
than
you should get something like:
than your "start wait process" function will look like
To make this function better, instead of hardcoding call to x2, you can pass it as a parameter.
The problem with this code though would be transfer of variables from x1 to x2. You have couple choices there, for example, you can have all variables defined in x1 and needed in x2:
1. declared as global
2. have an object declared as global, that contains all the variables.
3. have an object, that contains both functions and a variables.
but that would be up to you.