This isn't possible because for send
to work, the coroutine has to be waiting for input. yield
pauses a coroutine, and send
and next
unpause it. If the generator is calling send
, it can't simultaneously be paused and waiting for input.
If you could send
to an unpaused coroutine, the semantics would get really weird. Suppose that rc.send(rc)
line worked. Then send
would continue the execution of the coroutine from where it left off, which is the send call... but there is no value for send
to return, because we didn't hit a yield.
Suppose we return some dummy value and continue. Then the coroutine would execute until the next yield
. At that point, what happens? Does execution rewind so send
can return the yielded value? Does the yield
discard the value? Where does control flow go? There's no good answer.