mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-09 09:22:03 +00:00
Add util: safety execute coroutine
This commit is contained in:
parent
2957ff75ee
commit
c10f933ca5
1 changed files with 16 additions and 0 deletions
16
aiogram/utils/safe.py
Normal file
16
aiogram/utils/safe.py
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue