Created
January 7, 2016 22:33
-
-
Save jaysudodeveloper/db92c17dac8e29835222 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# wait for incoming data to consume with a for loop | |
def consume(): | |
while True: | |
data = yield | |
consumer = data # Aliase the data variable to ensure the generator stays "charged" | |
for i in consumer: # consume the data and return back to the while loop | |
print i | |
# Just a basic generator object for proof of concept | |
def in_gen(x): | |
for i in range(x): | |
yield i | |
consumer = consume() | |
data = in_gen(5) | |
consumer.send(None) # precharge the generator before sending data. this is a must | |
# as generator objescts dont start when intantiated | |
consumer.send(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment