Add util: safety execute coroutine

This commit is contained in:
Alex Root Junior 2017-11-11 12:38:11 +02:00
parent 2957ff75ee
commit c10f933ca5

16
aiogram/utils/safe.py Normal file
View file

@ -0,0 +1,16 @@
import typing
async def safe(coro: typing.Coroutine) -> (bool, typing.Any):
"""
Safety execute coroutine
Status - returns True if success otherwise False
:param coro:
:return: status and result
"""
try:
return True, await coro
except Exception as e:
return False, e