|
@@ -1,19 +1,27 @@
|
|
|
from typing import Awaitable, Callable, Union
|
|
|
|
|
|
-from .globals import connect_handlers, disconnect_handlers, shutdown_handlers, startup_handlers
|
|
|
+import justpy as jp
|
|
|
+
|
|
|
+from . import globals
|
|
|
|
|
|
|
|
|
def on_connect(self, handler: Union[Callable, Awaitable]):
|
|
|
- connect_handlers.append(handler)
|
|
|
+ globals.connect_handlers.append(handler)
|
|
|
|
|
|
|
|
|
def on_disconnect(self, handler: Union[Callable, Awaitable]):
|
|
|
- disconnect_handlers.append(handler)
|
|
|
+ globals.disconnect_handlers.append(handler)
|
|
|
|
|
|
|
|
|
def on_startup(self, handler: Union[Callable, Awaitable]):
|
|
|
- startup_handlers.append(handler)
|
|
|
+ globals.startup_handlers.append(handler)
|
|
|
|
|
|
|
|
|
def on_shutdown(self, handler: Union[Callable, Awaitable]):
|
|
|
- shutdown_handlers.append(handler)
|
|
|
+ globals.shutdown_handlers.append(handler)
|
|
|
+
|
|
|
+
|
|
|
+async def shutdown(self) -> None:
|
|
|
+ for socket in [s for page in jp.WebPage.sockets.values() for s in page.values()]:
|
|
|
+ await socket.close()
|
|
|
+ globals.server.should_exit = True
|