Skip to content

Commit

Permalink
feat: speed up SmartTask and SmartFuture init
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler committed Nov 23, 2024
1 parent 52b277a commit 251ada9
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 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,7 @@ 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 +299,7 @@ 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 251ada9

Please sign in to comment.