Coroutine based state machine.