Skip to content

Commit

Permalink
feat: optimize _asyncify helper (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored Dec 17, 2024
1 parent 3652792 commit 531d533
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion a_sync/a_sync/_helpers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ cdef object _await(object awaitable):
raise


cdef object _asyncify(object func, object executor): # type: ignore [misc]
cdef object _asyncify(object func, executor: Executor): # type: ignore [misc]
"""
Convert a synchronous function to a coroutine function using an executor.
Expand Down Expand Up @@ -93,6 +93,16 @@ cdef object _asyncify(object func, object executor): # type: ignore [misc]
if iscoroutinefunction(func) or isinstance(func, ASyncFunction):
raise exceptions.FunctionNotSync(func)

if hasattr(executor, "run"):
# ASyncExecutor classes are better optimized.
# TODO: implement the same optimizations in the else block below

run = executor.run

return wraps(func)(
lambda *args, **kwargs: run(func, *args, **kwargs)
)

cdef object submit = executor.submit

@wraps(func)
Expand Down

0 comments on commit 531d533

Please sign in to comment.