Reschedule the timeout.
(self, when: float | None)
| 46 | return self._when |
| 47 | |
| 48 | def reschedule(self, when: float | None) -> None: |
| 49 | """Reschedule the timeout.""" |
| 50 | if self._state is not _State.ENTERED: |
| 51 | if self._state is _State.CREATED: |
| 52 | raise RuntimeError("Timeout has not been entered") |
| 53 | raise RuntimeError( |
| 54 | f"Cannot change state of {self._state.value} Timeout", |
| 55 | ) |
| 56 | |
| 57 | self._when = when |
| 58 | |
| 59 | if self._timeout_handler is not None: |
| 60 | self._timeout_handler.cancel() |
| 61 | |
| 62 | if when is None: |
| 63 | self._timeout_handler = None |
| 64 | else: |
| 65 | loop = events.get_running_loop() |
| 66 | if when <= loop.time(): |
| 67 | self._timeout_handler = loop.call_soon(self._on_timeout) |
| 68 | else: |
| 69 | self._timeout_handler = loop.call_at(when, self._on_timeout) |
| 70 | |
| 71 | def expired(self) -> bool: |
| 72 | """Is timeout expired during execution?""" |