Debian Codegraph @

debian/vendor/hypercorn/trio/worker_context.py

raw
1 from __future__ import annotations
2
3 from typing import Type, Union
4
5 import trio
6
7 from ..typing import Event
8
9
10 class EventWrapper:
11 def __init__(self) -> None:
12 self._event = trio.Event()
13
14 async def clear(self) -> None:
15 self._event = trio.Event()
16
17 async def wait(self) -> None:
18 await self._event.wait()
19
20 async def set(self) -> None:
21 self._event.set()
22
23 def is_set(self) -> bool:
24 return self._event.is_set()
25
26
27 class WorkerContext:
28 event_class: Type[Event] = EventWrapper
29
30 def __init__(self) -> None:
31 self.terminated = self.event_class()
32
33 @staticmethod
34 async def sleep(wait: Union[float, int]) -> None:
35 return await trio.sleep(wait)
36
37 @staticmethod
38 def time() -> float:
39 return trio.current_time()