-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: nadine.loepfe <[email protected]>
- Loading branch information
1 parent
a611d01
commit 7ebe939
Showing
4 changed files
with
108 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import threading | ||
|
||
class SubscriptionHandle: | ||
""" | ||
Represents a handle to an ongoing subscription. | ||
Calling .cancel() will signal the subscription thread to stop. | ||
""" | ||
def __init__(self): | ||
self._cancelled = threading.Event() | ||
self._thread = None | ||
|
||
def cancel(self): | ||
""" | ||
Signals to cancel the subscription. | ||
""" | ||
self._cancelled.set() | ||
|
||
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): | ||
""" | ||
(Optional) Store the thread object for reference. | ||
""" | ||
self._thread = thread | ||
|
||
def join(self, timeout=None): | ||
""" | ||
(Optional) Wait for the subscription thread to end. | ||
""" | ||
if self._thread: | ||
self._thread.join(timeout) |