Skip to content

Instantly share code, notes, and snippets.

@cdent
Created July 17, 2009 02:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdent/148823 to your computer and use it in GitHub Desktop.
Save cdent/148823 to your computer and use it in GitHub Desktop.
from collections import deque
class Addable(object):
def __init__(self):
self.holder = deque()
def adder(self):
while True:
try:
self.holder.append((yield))
except GeneratorExit:
return
def show(self):
while True:
try:
yield self.holder.popleft()
except IndexError:
return
def do2():
a = Addable()
adder = a.adder()
shower = a.show()
adder.next()
for i in ['you', 'sexy', 'thing']:
adder.send(i)
print shower.next()
for i in ['YOU', 'SEXY', 'THING']:
adder.send(i)
print shower.next()
print "remains"
for remains in shower:
print remains
shower = a.show() # gotta reboot the shower
adder.send('so done now')
print shower.next()
if __name__ == '__main__':
do2()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment