Skip to content

Commit

Permalink
feat: optimize _asyncify (#484)
Browse files Browse the repository at this point in the history
* feat: optimize _asyncify

* Update _helpers.pyx

* Update _helpers.pyx
  • Loading branch information
BobTheBuidler authored Dec 16, 2024
1 parent 00ab898 commit 25e26cf
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions a_sync/a_sync/_helpers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ and converting synchronous functions to asynchronous ones.
"""

import asyncio
import functools
from asyncio import iscoroutinefunction
from asyncio.futures import wrap_future
from functools import wraps

from a_sync import exceptions
from a_sync._typing import *
Expand Down Expand Up @@ -88,16 +90,14 @@ cdef object _asyncify(object func, object executor): # type: ignore [misc]
"""
from a_sync.a_sync.function import ASyncFunction

if asyncio.iscoroutinefunction(func) or isinstance(func, ASyncFunction):
if iscoroutinefunction(func) or isinstance(func, ASyncFunction):
raise exceptions.FunctionNotSync(func)

cdef object sumbit

submit = executor.submit
cdef object submit = executor.submit

@functools.wraps(func)
@wraps(func)
async def _asyncify_wrap(*args: P.args, **kwargs: P.kwargs) -> T:
return await asyncio.futures.wrap_future(
return await wrap_future(
submit(func, *args, **kwargs),
loop=get_event_loop(),
)
Expand Down

0 comments on commit 25e26cf

Please sign in to comment.