draft of coroutine examples

This commit is contained in:
Luciano Ramalho
2015-02-17 10:07:07 -02:00
parent dfb3c3b895
commit e910ec5458
13 changed files with 326 additions and 25 deletions

12
control/coroutil.py Normal file
View File

@@ -0,0 +1,12 @@
# BEGIN CORO_DECO
from functools import wraps
def coroutine(func):
"""Decorator: primes `func` by advancing to first `yield`"""
@wraps(func)
def primer(*args,**kwargs): # <1>
gen = func(*args,**kwargs) # <2>
next(gen) # <3>
return gen # <4>
return primer
# END CORO_DECO