Created
January 18, 2024 14:25
-
-
Save Saik0s/263b7a4393238ba235df63b94c17e71d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async def run_async(func, *args, **kwargs) -> T: | |
""" | |
Runs a synchronous function in an asynchronous manner. | |
""" | |
async def wrapper() -> T: | |
try: | |
return await loop.run_in_executor( | |
None, functools.partial(func, *args, **kwargs) | |
) | |
except Exception as e: | |
# propagate the exception to the caller | |
raise e | |
loop = asyncio.get_event_loop() | |
return await wrapper() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment