mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-12-01 05:53:59 +03:00
9a785de4b5
* Add coroutine provider examples * Add coroutine provier * Update changelog * Update static analysis travis jobs to python 3.7 * Update coroutine provider implementation for python 3.4 * Update static analysis travis jobs to python 3.6 * Make pycode style happy * Add tests for coroutine providers * Make coroutine tests python 2 syntax friendly * Split tests to python2 and python3 * Refactor coroutine provider tests * Modify pypy tests running command * Update coroutine provider docs
27 lines
635 B
Python
27 lines
635 B
Python
"""`Coroutine` providers example with @asyncio.coroutine decorator.
|
|
|
|
Current example works only fot Python 3.4+.
|
|
"""
|
|
|
|
import asyncio
|
|
|
|
import dependency_injector.providers as providers
|
|
|
|
|
|
@asyncio.coroutine
|
|
def coroutine_function(arg1, arg2):
|
|
"""Sample coroutine function."""
|
|
yield from asyncio.sleep(0.1)
|
|
return arg1, arg2
|
|
|
|
|
|
coroutine_provider = providers.Coroutine(coroutine_function, arg1=1, arg2=2)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
loop = asyncio.get_event_loop()
|
|
arg1, arg2 = loop.run_until_complete(coroutine_provider())
|
|
|
|
assert (arg1, arg2) == (1, 2)
|
|
assert asyncio.iscoroutinefunction(coroutine_provider)
|