I mostly use yields with signals to pause a function until an animation is finished. A common use case, to my understanding.
One problem I regularly run into is when I want to refactor a chunk of code that's yielding.
Say I have the following code:
yield(get_node("AnimationPlayer"), "finished" )
and I end up wanting to refactor the first 3 lines into its own function call.
So I abstract it out and now the code is
But the problem is that after refactoring,
doing_stuff_1_and_2() returns immediately upon yielding, and so
do_some_more_stuff() is called before the Animation is finished.
This is frustrating to me because (and admittedly I haven't worked with coroutines before) I'm not used to refactoring changing the execution flow of my code.
How do people work around this? Maybe some sort of outside control structure?
How I've been doing it is just emitting another signal when
doing_stuff_1_and_2() is complete and yielding to that in the main function, but I feel like this isn't a good solution since more signals leads to harder to track execution flow.