clan-lib: Remove injected "op_key" argument from all functions and do it over the threadcontext instead. Remove double threading in http server

This commit is contained in:
Qubasa
2025-07-24 14:25:05 +07:00
parent 0ffad32657
commit 94662b722d
7 changed files with 80 additions and 60 deletions

View File

@@ -74,6 +74,7 @@ class AsyncContext:
should_cancel: Callable[[], bool] = (
lambda: False
) # Used to signal cancellation of task
op_key: str | None = None
@dataclass
@@ -90,6 +91,22 @@ class AsyncOpts:
ASYNC_CTX_THREAD_LOCAL = threading.local()
def set_current_thread_opkey(op_key: str) -> None:
"""
Set the current thread's operation key.
"""
ctx = get_async_ctx()
ctx.op_key = op_key
def get_current_thread_opkey() -> str | None:
"""
Get the current thread's operation key.
"""
ctx = get_async_ctx()
return ctx.op_key
def is_async_cancelled() -> bool:
"""
Check if the current task has been cancelled.