coroutine¶
-
support.coroutine.
coroutine
(func)¶ Simple decorator to “prime” a coroutine
Uses Python 2.5 extension to decorators, in which ‘yield’ has a return value other than None when the ‘send()’ is invoked. Then ‘yield’ returns the received value.
Examples:
@coroutine def my_coroutine(): while True: input = (yield) print(input) c = my_coroutine() # no need to call next(c) c.send("hey") c.send("my") c.send("name")
When run, this will produce the following output:
hey my name