I'm not sure what you are doing, but coroutines are used for waiting for an event to finish. You might want to check them out in the docs. However, you can't put them in a process function, which is probably your problem with using them in a while loop.