Skip to content

Commit e591d11

Browse files
More field types
1 parent 525d9ac commit e591d11

File tree

1 file changed

+35
-9
lines changed

1 file changed

+35
-9
lines changed

src/replit_river/session.py

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import asyncio
22
import logging
3-
from typing import Any, Awaitable, Callable, Coroutine
3+
from typing import Any, Awaitable, Callable, Coroutine, TypeAlias
44

55
import nanoid
66
import websockets
@@ -37,25 +37,51 @@
3737
trace_propagator = TraceContextTextMapPropagator()
3838
trace_setter = TransportMessageTracingSetter()
3939

40+
CloseSessionCallback: TypeAlias = Callable[["Session"], Coroutine[Any, Any, Any]]
41+
RetryConnectionCallback: TypeAlias = Callable[
42+
[],
43+
Coroutine[Any, Any, Any],
44+
]
45+
4046

4147
class Session:
4248
"""Common functionality shared between client_session and server_session"""
4349

50+
_transport_id: str
51+
_to_id: str
52+
session_id: str
53+
_transport_options: TransportOptions
54+
55+
# session state
56+
_state: SessionState
57+
_state_lock: asyncio.Lock
58+
_close_session_callback: CloseSessionCallback
59+
_close_session_after_time_secs: float | None
60+
61+
# ws state
62+
_ws_lock: asyncio.Lock
63+
_ws_wrapper: WebsocketWrapper
64+
_heartbeat_misses: int
65+
_retry_connection_callback: RetryConnectionCallback | None
66+
67+
# stream for tasks
68+
_streams: dict[str, Channel[Any]]
69+
70+
# book keeping
71+
_seq_manager: SeqManager
72+
_msg_lock: asyncio.Lock
73+
_buffer: MessageBuffer
74+
_task_manager: BackgroundTaskManager
75+
4476
def __init__(
4577
self,
4678
transport_id: str,
4779
to_id: str,
4880
session_id: str,
4981
websocket: websockets.WebSocketCommonProtocol,
5082
transport_options: TransportOptions,
51-
close_session_callback: Callable[["Session"], Coroutine[Any, Any, Any]],
52-
retry_connection_callback: (
53-
Callable[
54-
[],
55-
Coroutine[Any, Any, Any],
56-
]
57-
| None
58-
) = None,
83+
close_session_callback: CloseSessionCallback,
84+
retry_connection_callback: RetryConnectionCallback | None = None,
5985
) -> None:
6086
self._transport_id = transport_id
6187
self._to_id = to_id

0 commit comments

Comments
 (0)