Skip to content

Commit

Permalink
Revert removing of SyncToAsync.get_current_task
Browse files Browse the repository at this point in the history
  • Loading branch information
legau committed Mar 21, 2024
1 parent 852344e commit 6ba6881
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions asgiref/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,16 @@ def thread_handler(self, loop, exc_info, task_context, func, *args, **kwargs):
else:
return func(*args, **kwargs)

@staticmethod
def get_current_task() -> Optional["asyncio.Task[Any]"]:
"""
Implementation of asyncio.current_task()
that returns None if there is no task.
"""
try:
return asyncio.current_task()
except RuntimeError:
return None

@overload
def async_to_sync(
Expand Down

0 comments on commit 6ba6881

Please sign in to comment.