File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -25,18 +25,30 @@ class _State(enum.Enum):
25
25
26
26
@final
27
27
class Timeout :
28
+ """Asynchronous context manager for cancelling overdue coroutines.
29
+
30
+ Use `timeout()` or `timeout_at()` rather than instantiating this class directly.
31
+ """
28
32
29
33
def __init__ (self , when : Optional [float ]) -> None :
34
+ """Schedule a timeout that will trigger at a given loop time.
35
+
36
+ - If `when` is `None`, the timeout will never trigger.
37
+ - If `when < loop.time()`, the timeout will trigger on the next
38
+ iteration of the event loop.
39
+ """
30
40
self ._state = _State .CREATED
31
41
32
42
self ._timeout_handler : Optional [events .TimerHandle ] = None
33
43
self ._task : Optional [tasks .Task ] = None
34
44
self ._when = when
35
45
36
46
def when (self ) -> Optional [float ]:
47
+ """Return the current deadline."""
37
48
return self ._when
38
49
39
50
def reschedule (self , when : Optional [float ]) -> None :
51
+ """Reschedule the timeout."""
40
52
assert self ._state is not _State .CREATED
41
53
if self ._state is not _State .ENTERED :
42
54
raise RuntimeError (
You can’t perform that action at this time.
0 commit comments