-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsubscriberState.py
25 lines (20 loc) · 1.05 KB
/
subscriberState.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# this will be used to generate human readable names for each subscription
from coolname import generate_slug
# Using a class to handle out of scope variables or functionality as asyncio is used.
# This is one of the Python ways of avoiding globals, and or providing "global-like" functionality
class SubscriberState :
def __init__(self) :
# this property is used to control the loop keeping the wait state open to recieve messages
self._open : bool = True
# generate a coolname for this subscriber
self._subscriberName : str = generate_slug(2)
# this method will be used to top the iteration that keeps the subscriber open
# a .wait() method could be added here to keep the connection alive as well
def closeConnection(self) -> None :
self._open = False
# identifies if the subscriber state is stile alive
def hasOpenConnection(self) -> bool :
return self._open
# returns the name of the subscriber process
def getSubsriberName(self) -> str :
return self._subscriberName