-
-
Notifications
You must be signed in to change notification settings - Fork 324
/
Copy pathtypes.py
43 lines (28 loc) · 1.13 KB
/
types.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 threading import Thread
from typing import Optional, TypeVar
from typing_extensions import Protocol
from idom.core.types import ComponentConstructor
_App = TypeVar("_App")
_Config = TypeVar("_Config", contravariant=True)
class ServerFactory(Protocol[_App, _Config]):
"""Setup a :class:`Server`"""
def __call__(
self,
constructor: ComponentConstructor,
config: Optional[_Config] = None,
app: Optional[_App] = None,
) -> ServerType[_App]:
...
class ServerType(Protocol[_App]):
"""A thin wrapper around a web server that provides a common operational interface"""
app: _App
"""The server's underlying application"""
def run(self, host: str, port: int) -> None:
"""Start running the server"""
def run_in_thread(self, host: str, port: int) -> Thread:
"""Run the server in a thread"""
def wait_until_started(self, timeout: Optional[float] = None) -> None:
"""Block until the server is able to receive requests"""
def stop(self, timeout: Optional[float] = None) -> None:
"""Stop the running server"""