summaryrefslogtreecommitdiff
path: root/venv/lib/python3.11/site-packages/litestar/channels/backends/base.py
diff options
context:
space:
mode:
authorcyfraeviolae <cyfraeviolae>2024-04-03 03:10:44 -0400
committercyfraeviolae <cyfraeviolae>2024-04-03 03:10:44 -0400
commit6d7ba58f880be618ade07f8ea080fe8c4bf8a896 (patch)
treeb1c931051ffcebd2bd9d61d98d6233ffa289bbce /venv/lib/python3.11/site-packages/litestar/channels/backends/base.py
parent4f884c9abc32990b4061a1bb6997b4b37e58ea0b (diff)
venv
Diffstat (limited to 'venv/lib/python3.11/site-packages/litestar/channels/backends/base.py')
-rw-r--r--venv/lib/python3.11/site-packages/litestar/channels/backends/base.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/venv/lib/python3.11/site-packages/litestar/channels/backends/base.py b/venv/lib/python3.11/site-packages/litestar/channels/backends/base.py
new file mode 100644
index 0000000..ce7ee81
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/litestar/channels/backends/base.py
@@ -0,0 +1,41 @@
+from __future__ import annotations
+
+from abc import ABC, abstractmethod
+from typing import AsyncGenerator, Iterable
+
+
+class ChannelsBackend(ABC):
+ @abstractmethod
+ async def on_startup(self) -> None:
+ """Called by the plugin on application startup"""
+ ...
+
+ @abstractmethod
+ async def on_shutdown(self) -> None:
+ """Called by the plugin on application shutdown"""
+ ...
+
+ @abstractmethod
+ async def publish(self, data: bytes, channels: Iterable[str]) -> None:
+ """Publish the message ``data`` to all ``channels``"""
+ ...
+
+ @abstractmethod
+ async def subscribe(self, channels: Iterable[str]) -> None:
+ """Start listening for events on ``channels``"""
+ ...
+
+ @abstractmethod
+ async def unsubscribe(self, channels: Iterable[str]) -> None:
+ """Stop listening for events on ``channels``"""
+ ...
+
+ @abstractmethod
+ def stream_events(self) -> AsyncGenerator[tuple[str, bytes], None]:
+ """Return a generator, iterating over events of subscribed channels as they become available"""
+ ...
+
+ @abstractmethod
+ async def get_history(self, channel: str, limit: int | None = None) -> list[bytes]:
+ """Return the event history of ``channel``, at most ``limit`` entries"""
+ ...