Skip to content

Commit

Permalink
feat: speed up SmartTask and SmartFuture init (#433)
Browse files Browse the repository at this point in the history
* feat: speed up SmartTask and SmartFuture init

* chore: `black .`

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
BobTheBuidler and github-actions[bot] authored Nov 23, 2024
1 parent 0167fff commit 8bc2aba
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions a_sync/_smart.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""

import asyncio
import contextvars
import logging
import warnings
import weakref
Expand Down Expand Up @@ -197,7 +198,9 @@ def __init__(
if key:
self._key = key
self._waiters = weakref.WeakSet()
self.add_done_callback(SmartFuture._self_done_cleanup_callback)
self._callbacks.append(
(SmartFuture._self_done_cleanup_callback, contextvars.copy_context())
)

def __repr__(self):
return f"<{type(self).__name__} key={self._key} waiters={self.num_waiters} {self._state}>"
Expand Down Expand Up @@ -298,7 +301,9 @@ def __init__(
"""
asyncio.Task.__init__(self, coro, loop=loop, name=name)
self._waiters: Set["asyncio.Task[T]"] = set()
self.add_done_callback(SmartTask._self_done_cleanup_callback)
self._callbacks.append(
(SmartTask._self_done_cleanup_callback, contextvars.copy_context())
)


def smart_task_factory(
Expand Down

0 comments on commit 8bc2aba

Please sign in to comment.