Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Coroutine pipeline
Coroutine pipeline.
Based off
import types
if __name__ == '__main__':
def receive(prod):
return prod.send(None)
def send(x):
yield x
async def producer():
while True:
x = input("? ")
await send(x)
def filter(prod):
async def _filter():
line = 1
while True:
x = receive(prod)
await send("%5d %s" % (line, x))
line = line + 1
return _filter()
def consumer(prod):
while True:
x = receive(prod)
# Simple pipeline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment