Skip to content

Commit

Permalink
feat: optimize _asyncify (#486)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored Dec 16, 2024
1 parent 43c684d commit 27f3ab3
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions a_sync/a_sync/_helpers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 27f3ab3

Please sign in to comment.