Coroutine not working how I think it would?

This scenario baffles me. Maybe it’s because I don’t fully grasp coroutines. Disclaimer: I have read the documentation on coroutines and watched the Unity tutorial.

So here’s the code in question:

if (isSubmerged && !isGettingReadyToEmerge)
        {
            
            StartCoroutine(EmergeTimer(1.2f)); //don't call this when isGettingReadyToEmerge==true!

        }
//...
IEnumerator EmergeTimer(float time) 
    {

       
            print("waiting to move... " + frameCount);
            yield return new WaitForSeconds(time);
            print("moving now! - while gettingrdy was " + isGettingReadyToEmerge + " " + frameCount);
            transform.position = playerTransform.position; 
            isGettingReadyToEmerge = true; //statement is here to prevent another call
            
        
    }

Ok, so I would expect the IEnumerator above to never happen while isGettingReadyToEmerge is true. But here’s some unity logs that proves me wrong:

83740-example.png

what am I missing?

The following will clear things up for you. (I removed your print commands so you can see what I did easier)

if (isSubmerged && !isGettingReadyToEmerge)
{
    StartCoroutine(EmergeTimer(1.2f)); //don't call this when isGettingReadyToEmerge==true!
}

IEnumerator EmergeTimer(float time) 
{
    isGettingReadyToEmerge = true; //flag to prevent coroutine from being called while it is being executed

    yield return new WaitForSeconds(time);

    transform.position = playerTransform.position; 
    isGettingReadyToEmerge = false; // coroutine is finished and can be called again
}