Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: optimize _asyncify #484

Merged
merged 3 commits into from
Dec 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading