2020-09-02 04:39:23 +03:00
|
|
|
"""`Coroutine` providers example with async / await syntax."""
|
2018-10-18 19:39:19 +03:00
|
|
|
|
|
|
|
import asyncio
|
|
|
|
|
2020-09-02 04:39:23 +03:00
|
|
|
from dependency_injector import providers
|
2018-10-18 19:39:19 +03:00
|
|
|
|
|
|
|
|
2020-09-02 04:39:23 +03:00
|
|
|
async def coroutine(arg1, arg2):
|
|
|
|
await asyncio.sleep(0.1)
|
2018-10-18 19:39:19 +03:00
|
|
|
return arg1, arg2
|
|
|
|
|
|
|
|
|
2020-09-02 04:39:23 +03:00
|
|
|
coroutine_provider = providers.Coroutine(coroutine, arg1=1, arg2=2)
|
2018-10-18 19:39:19 +03:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2020-09-02 04:39:23 +03:00
|
|
|
arg1, arg2 = asyncio.run(coroutine_provider())
|
2018-10-18 19:39:19 +03:00
|
|
|
assert (arg1, arg2) == (1, 2)
|
|
|
|
assert asyncio.iscoroutinefunction(coroutine_provider)
|