-
-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use server protocol instea of inheritance
- Loading branch information
Showing
13 changed files
with
133 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
from .base import AbstractRenderServer | ||
from .prefab import hotswap_server, multiview_server, run | ||
|
||
|
||
__all__ = [ | ||
"default", | ||
"run", | ||
"multiview_server", | ||
"hotswap_server", | ||
"AbstractRenderServer", | ||
"multiview_server", | ||
"run", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Optional, TypeVar | ||
|
||
from idom.core.component import ComponentConstructor | ||
|
||
|
||
try: | ||
from typing import Protocol | ||
except ImportError: | ||
from typing_extensions import Protocol # type: ignore | ||
|
||
|
||
_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, | ||
) -> Server[_App]: | ||
... | ||
|
||
|
||
class Server(Protocol[_App]): | ||
"""An object representing a server prepared to support IDOM's protocols""" | ||
|
||
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) -> None: | ||
"""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""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.