Skip to content
Snippets Groups Projects
Commit 1b20d3bf authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

fix docs

Change-Id: Ib40568bd0795538a20de855873d8c49f53bb9068
parent 903df7dc
No related branches found
No related tags found
No related merge requests found
......@@ -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):
......
......@@ -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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment