Skip to content

Commit

Permalink
fix: match asyncio.create_task api
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored Feb 3, 2024
1 parent 0af4a34 commit ed78cee
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions a_sync/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

logger = logging.getLogger(__name__)

def create_task(awaitable: Awaitable[_T], *, name: Optional[str] = None, skip_gc_until_done: bool = False) -> "asyncio.Task[_T]":
def create_task(coro: Awaitable[_T], *, name: Optional[str] = None, skip_gc_until_done: bool = False) -> "asyncio.Task[_T]":
"""A wrapper over `asyncio.create_task` which will work with any `Awaitable` object, not just `Coroutine` objects"""
coro = awaitable if asyncio.iscoroutine(awaitable) else __await(awaitable)
if not asyncio.iscoroutine(coro):
coro = __await(coro)
task = asyncio.create_task(coro, name=name)
if skip_gc_until_done:
__persist(task)
Expand All @@ -30,4 +31,4 @@ def __prune_persisted_tasks():
if e := task.exception():
logger.exception(e)
raise e
__persisted_tasks.discard(task)
__persisted_tasks.discard(task)

0 comments on commit ed78cee

Please sign in to comment.