@@ -85,15 +85,11 @@ async def connect(self):
85
85
self ._client = await SocketClient .connect (
86
86
config ,
87
87
None ,
88
+ # self.post_connection, # this method itself needs the `self._client` reference
88
89
self .post_reconnection ,
89
- None ,
90
- # TODO - waiting for async handling
91
- # self.post_connection,
92
- # self.post_reconnection,
93
- # self.post_disconnection,
90
+ self .post_disconnection ,
94
91
)
95
- self ._log .debug ("Running post connect" )
96
- await self .post_connection ()
92
+ await self ._post_connection ()
97
93
98
94
self .is_connected = True
99
95
self ._log .info ("Connected" )
@@ -108,9 +104,6 @@ async def reconnect(self):
108
104
109
105
await self ._client .reconnect ()
110
106
111
- self ._log .debug ("Running post connection" )
112
- await self .post_connection ()
113
-
114
107
self .is_connected = True
115
108
self ._log .info ("Reconnected" )
116
109
@@ -124,13 +117,13 @@ async def disconnect(self):
124
117
125
118
await self ._client .close ()
126
119
127
- self ._log .debug ("Running post disconnect" )
128
- await self .post_disconnection ()
129
-
130
120
self .is_connected = False
131
121
self ._log .info ("Disconnected" )
132
122
133
- async def post_connection (self ) -> None :
123
+ async def _post_connection (self ) -> None :
124
+ pass
125
+
126
+ def post_connection (self ) -> None :
134
127
"""
135
128
Actions to be performed post connection.
136
129
"""
@@ -140,13 +133,12 @@ def post_reconnection(self) -> None:
140
133
Actions to be performed post connection.
141
134
"""
142
135
143
- async def post_disconnection (self ) -> None :
136
+ def post_disconnection (self ) -> None :
144
137
"""
145
138
Actions to be performed post disconnection.
146
139
"""
147
140
148
141
async def send (self , message : bytes ) -> None :
149
- self ._log .debug (f"[SEND] { message .decode ()} " )
150
142
if self ._client is None :
151
143
raise RuntimeError ("Cannot send message: no client" )
152
144
@@ -201,8 +193,13 @@ def __init__(
201
193
"partitionMatchedByStrategyRef" : partition_matched_by_strategy_ref ,
202
194
}
203
195
204
- async def post_connection (self ):
205
- await super ().post_connection ()
196
+ def post_connection (self ):
197
+ self ._loop .create_task (self ._post_connection ())
198
+
199
+ def post_reconnection (self ):
200
+ self ._loop .create_task (self ._post_connection ())
201
+
202
+ async def _post_connection (self ):
206
203
subscribe_msg = {
207
204
"op" : "orderSubscription" ,
208
205
"id" : self .unique_id ,
@@ -213,10 +210,6 @@ async def post_connection(self):
213
210
await self .send (msgspec .json .encode (self .auth_message ()))
214
211
await self .send (msgspec .json .encode (subscribe_msg ))
215
212
216
- def post_reconnection (self ):
217
- super ().post_reconnection ()
218
- self ._loop .create_task (self .post_connection ())
219
-
220
213
221
214
class BetfairMarketStreamClient (BetfairStreamClient ):
222
215
"""
@@ -319,10 +312,12 @@ async def send_subscription_message(
319
312
}
320
313
await self .send (msgspec .json .encode (message ))
321
314
322
- async def post_connection (self ) -> None :
323
- await super ().post_connection ()
324
- await self .send (msgspec .json .encode (self .auth_message ()))
315
+ def post_connection (self ) -> None :
316
+ self ._loop .create_task (self ._post_connection ())
325
317
326
318
def post_reconnection (self ) -> None :
327
319
super ().post_reconnection ()
328
- self ._loop .create_task (self .post_connection ())
320
+ self ._loop .create_task (self ._post_connection ())
321
+
322
+ async def _post_connection (self ) -> None :
323
+ await self .send (msgspec .json .encode (self .auth_message ()))
0 commit comments