This is kind of a weird question so I'll explain:
I have a generator like this that is acting as a generator frontend to an IRC server:
def irc_iter(): # not the real code, simplified
msgs = get_msgs()
for msg in msgs:
if is_ping(msg):
pong()
else:
to_send = yield msg
for s in to_send:
send(s)
This, theoretically, should allow me to do something cool, like:
server = connect()
for line in server:
if should_respond(line):
server.send('WOW SUCH MESSAGE')
However, there's a hitch: generator.send
yields the next value as well. This means that server.send
is also giving me the next message... which I would prefer to handle like all the other messages, yielded as line
.
I know I can fix this in an ugly way, by just yielding a junk value after receiving a send, but I'm trying to keep my code elegant and that is the opposite. Is there a way to just tell the generator I don't want a new value yet?
Thanks.