def run_coroutine(coro):
    """Runs a coroutine as top-level task by iterating through all yielded steps."""

    result = None
    try:
        # step through all parts of coro without scheduling anything else:
        while True:
            result = coro.send(result)
    except StopIteration as ex:
        # coro reached end pass on its return value:
        return ex.value
    except:
        raise