-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
service.py
43 lines (30 loc) · 1.07 KB
/
service.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from __future__ import annotations
from typing import TYPE_CHECKING, Set
from launart import Launart, Service, any_completed
from .net.ws_client import RedWsClientNetworking
if TYPE_CHECKING:
from .protocol import RedProtocol
class RedService(Service):
id = "red.service"
protocol: RedProtocol
connections: list[RedWsClientNetworking]
def __init__(self, protocol: RedProtocol):
self.protocol = protocol
self.connections = []
super().__init__()
async def launch(self, manager: Launart):
async with self.stage("preparing"):
for i in self.connections:
manager.add_component(i)
async with self.stage("blocking"):
await any_completed(
manager.status.wait_for_sigexit(), *(i.status.wait_for("blocking-completed") for i in self.connections)
)
async with self.stage("cleanup"):
...
@property
def stages(self):
return {"preparing", "blocking", "cleanup"}
@property
def required(self) -> Set[str]:
return set()