diff options
-rw-r--r-- | src/argaze/DataStructures.py | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/src/argaze/DataStructures.py b/src/argaze/DataStructures.py index cf5bc3a..6e058e8 100644 --- a/src/argaze/DataStructures.py +++ b/src/argaze/DataStructures.py @@ -107,6 +107,7 @@ class SharedObject(): def __init__(self): self._lock = threading.Lock() self._timestamp = math.nan + self._token = None def acquire(self): self._lock.acquire() @@ -121,13 +122,54 @@ class SharedObject(): def timestamp(self) -> int|float: """Get timestamp""" - return self._timestamp + self._lock.acquire() + timestamp = self._timestamp + self._lock.release() + + return timestamp @timestamp.setter def timestamp(self, timestamp: int|float): """Set timestamp""" + self._lock.acquire() self._timestamp = timestamp + self._lock.release() + + def untimestamp(self): + """Reset timestamp""" + + self._lock.acquire() + self._timestamp = math.nan + self._lock.release() + + @property + def timestamped(self) -> bool: + """Is the object timestamped?""" + + self._lock.acquire() + timestamped = not math.isnan(self._timestamp) + self._lock.release() + + return timestamped + + @property + def token(self) -> any: + """Get token""" + + self._lock.acquire() + token = self._token + self._lock.release() + + return token + + @token.setter + def token(self, token: any): + """Set token""" + + self._lock.acquire() + self._token = token + self._lock.release() class TimeStampedBuffer(collections.OrderedDict): """Ordered dictionary to handle timestamped data. |