diff --git a/satella/coding/concurrent/timer.py b/satella/coding/concurrent/timer.py index bdc5a3eb1e1bedaa51be707db836ebf78ceedc6f..0b990103c69605f9c5e0baa7b3fff027bf8de3ff 100644 --- a/satella/coding/concurrent/timer.py +++ b/satella/coding/concurrent/timer.py @@ -20,17 +20,16 @@ class Timer: There might be up to a second of delay before the timer is picked up. - If spawn_separate is False, exceptions will be logged +n If spawn_separate is False, exceptions will be logged. - :param interval: amount of seconds that should elapsed between calling start() and function + :param interval: amount of seconds that should elapse between calling start() and function executing. Can be also a time string. :param function: function to execute :param args: argument for function :param kwargs: kwargs for function :param spawn_separate: whether to call the function in a separate thread """ - __slots__ = ('args', 'kwargs', 'spawn_separate', 'interval', - 'function', 'execute_at', 'cancelled') + __slots__ = 'args', 'kwargs', 'spawn_separate', 'interval', 'function', 'execute_at', 'cancelled' def __init__(self, interval: tp.Union[str, float], function, args=None, kwargs=None, spawn_separate=False): diff --git a/satella/coding/concurrent/value.py b/satella/coding/concurrent/value.py index 2bd1de4f0e13a4b0b0429b423abf594caa100918..71bd9be88a7248dccd4810f1d4bdb4728832f83d 100644 --- a/satella/coding/concurrent/value.py +++ b/satella/coding/concurrent/value.py @@ -2,14 +2,11 @@ import time import typing as tp from threading import Event +from satella.coding.misc import _BLANK from satella.coding.typing import T from satella.exceptions import WouldWaitMore -class _UNSET: - pass - - class DeferredValue(tp.Generic[T]): """ A class that allows you to pass arguments that will be available later during runtime. @@ -29,7 +26,7 @@ class DeferredValue(tp.Generic[T]): def __init__(self): self.lock = Event() - self.val = _UNSET + self.val = _BLANK def set_value(self, va: T) -> None: """ @@ -38,7 +35,7 @@ class DeferredValue(tp.Generic[T]): :param va: value to set :raises ValueError: value is already set """ - if self.val is not _UNSET: + if self.val is not _BLANK: raise ValueError('Value curently set!') self.val = va self.lock.set() @@ -49,13 +46,13 @@ class DeferredValue(tp.Generic[T]): def value(self, timeout: tp.Optional[float] = None) -> T: """ - Wait until value is available. + Wait until value is available, and return it. :param timeout: number of seconds to wait. If None is given, this will take as long as necessary. :return: a value :raises WouldWaitMore: timeout was given and it has expired """ - if self.val is not _UNSET: + if self.val is not _BLANK: return self.val tout = self.lock.wait(timeout) if not tout: