From 27f3ab30335e8c7ec82565b5ebccc892a4c09859 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Mon, 16 Dec 2024 04:03:00 -0400 Subject: [PATCH] feat: optimize _asyncify (#486) --- a_sync/a_sync/_helpers.pyx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/a_sync/a_sync/_helpers.pyx b/a_sync/a_sync/_helpers.pyx index 1080c321..b0b0db06 100644 --- a/a_sync/a_sync/_helpers.pyx +++ b/a_sync/a_sync/_helpers.pyx @@ -5,7 +5,7 @@ and converting synchronous functions to asynchronous ones. from asyncio import iscoroutinefunction, new_event_loop, set_event_loop from asyncio import get_event_loop as _get_event_loop -from asyncio.futures import wrap_future +from asyncio.futures import _chain_future from functools import wraps from a_sync import exceptions @@ -97,9 +97,10 @@ cdef object _asyncify(object func, object executor): # type: ignore [misc] @wraps(func) async def _asyncify_wrap(*args: P.args, **kwargs: P.kwargs) -> T: - return await wrap_future( - submit(func, *args, **kwargs), - loop=get_event_loop(), - ) + loop = get_event_loop() + fut = loop.create_future() + cf_fut = submit(func, *args, **kwargs) + _chain_future(cf_fut, fut) + return await fut return _asyncify_wrap