Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/hiero_sdk_python/utils/subscription_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class SubscriptionHandle:
Calling .cancel() will signal the subscription thread to stop.
"""

def __init__(self):
def __init__(self) -> None:
self._cancelled = threading.Event()
self._thread: threading.Thread | None = None
self._call: Any | None = None
self._lock = threading.Lock()

def _set_call(self, call: Any):
def _set_call(self, call: Any) -> None:
"""Sets the active gRPC call so it can be cancelled."""
should_cancel = False

Expand All @@ -30,7 +30,7 @@ def _set_call(self, call: Any):
if should_cancel:
self._call.cancel()

def cancel(self):
def cancel(self) -> None:
"""Signals to cancel the subscription."""
should_cancel = False

Expand All @@ -47,11 +47,16 @@ def is_cancelled(self) -> bool:
"""Returns True if this subscription is already cancelled."""
return self._cancelled.is_set()

def set_thread(self, thread: threading.Thread):
def set_thread(self, thread: threading.Thread) -> None:
"""(Optional) Store the thread object for reference."""
self._thread = thread

def join(self, timeout=None):
"""(Optional) Wait for the subscription thread to end."""
def join(self, timeout: float | None = None) -> None:
"""(Optional) Wait for the subscription thread to end.

Args:
timeout: Maximum time to wait in seconds. ``None`` means
wait indefinitely.
"""
if self._thread:
self._thread.join(timeout)
Loading