1
1
import asyncio
2
2
import concurrent .futures
3
3
import typing
4
- from typing import List , Union , Iterable , Optional , Coroutine
4
+ from typing import List , Union , Iterable , Optional
5
5
6
6
from ydb ._grpc .grpcwrapper .common_utils import SupportedDriverType
7
7
from ydb ._topic_common .common import _get_shared_event_loop , CallFromSyncToAsync
@@ -24,11 +24,11 @@ class TopicReaderSync:
24
24
_closed : bool
25
25
26
26
def __init__ (
27
- self ,
28
- driver : SupportedDriverType ,
29
- settings : PublicReaderSettings ,
30
- * ,
31
- eventloop : Optional [asyncio .AbstractEventLoop ] = None ,
27
+ self ,
28
+ driver : SupportedDriverType ,
29
+ settings : PublicReaderSettings ,
30
+ * ,
31
+ eventloop : Optional [asyncio .AbstractEventLoop ] = None ,
32
32
):
33
33
self ._closed = False
34
34
@@ -70,7 +70,7 @@ async def sessions_stat(self) -> List[SessionStat]:
70
70
raise NotImplementedError ()
71
71
72
72
def messages (
73
- self , * , timeout : Union [float , None ] = None
73
+ self , * , timeout : Union [float , None ] = None
74
74
) -> Iterable [PublicMessage ]:
75
75
"""
76
76
todo?
@@ -104,11 +104,11 @@ def async_wait_message(self) -> concurrent.futures.Future:
104
104
raise NotImplementedError ()
105
105
106
106
def batches (
107
- self ,
108
- * ,
109
- max_messages : Union [int , None ] = None ,
110
- max_bytes : Union [int , None ] = None ,
111
- timeout : Union [float , None ] = None ,
107
+ self ,
108
+ * ,
109
+ max_messages : Union [int , None ] = None ,
110
+ max_bytes : Union [int , None ] = None ,
111
+ timeout : Union [float , None ] = None ,
112
112
) -> Iterable [PublicBatch ]:
113
113
"""
114
114
Block until receive new batch.
@@ -120,11 +120,11 @@ def batches(
120
120
raise NotImplementedError ()
121
121
122
122
def receive_batch (
123
- self ,
124
- * ,
125
- max_messages : typing .Union [int , None ] = None ,
126
- max_bytes : typing .Union [int , None ] = None ,
127
- timeout : Union [float , None ] = None ,
123
+ self ,
124
+ * ,
125
+ max_messages : typing .Union [int , None ] = None ,
126
+ max_bytes : typing .Union [int , None ] = None ,
127
+ timeout : Union [float , None ] = None ,
128
128
) -> Union [PublicBatch , None ]:
129
129
"""
130
130
Get one messages batch from reader
@@ -136,10 +136,15 @@ def receive_batch(
136
136
self ._check_closed ()
137
137
138
138
return self ._caller .safe_call_with_result (
139
- self ._async_reader .receive_batch (max_messages = max_messages , max_bytes = max_bytes ),
140
- timeout )
141
-
142
- def commit (self , mess : typing .Union [datatypes .PublicMessage , datatypes .PublicBatch ]):
139
+ self ._async_reader .receive_batch (
140
+ max_messages = max_messages , max_bytes = max_bytes
141
+ ),
142
+ timeout ,
143
+ )
144
+
145
+ def commit (
146
+ self , mess : typing .Union [datatypes .PublicMessage , datatypes .PublicBatch ]
147
+ ):
143
148
"""
144
149
Put commit message to internal buffer.
145
150
@@ -151,7 +156,7 @@ def commit(self, mess: typing.Union[datatypes.PublicMessage, datatypes.PublicBat
151
156
self ._caller .call_sync (self ._async_reader .commit (mess ))
152
157
153
158
def commit_with_ack (
154
- self , mess : ICommittable , timeout : typing .Union [int , float , None ] = None
159
+ self , mess : ICommittable , timeout : typing .Union [int , float , None ] = None
155
160
) -> Union [CommitResult , List [CommitResult ]]:
156
161
"""
157
162
write commit message to a buffer and wait ack from the server.
@@ -160,15 +165,21 @@ def commit_with_ack(
160
165
"""
161
166
self ._check_closed ()
162
167
163
- return self ._caller .unsafe_call_with_result (self ._async_reader .commit_with_ack (mess ), timeout )
168
+ return self ._caller .unsafe_call_with_result (
169
+ self ._async_reader .commit_with_ack (mess ), timeout
170
+ )
164
171
165
- def async_commit_with_ack (self , mess : typing .Union [datatypes .PublicMessage , datatypes .PublicBatch ]) -> concurrent .futures .Future :
172
+ def async_commit_with_ack (
173
+ self , mess : typing .Union [datatypes .PublicMessage , datatypes .PublicBatch ]
174
+ ) -> concurrent .futures .Future :
166
175
"""
167
176
write commit message to a buffer and return Future for wait result.
168
177
"""
169
178
self ._check_closed ()
170
179
171
- return self ._caller .unsafe_call_with_future (self ._async_reader .commit_with_ack (mess ))
180
+ return self ._caller .unsafe_call_with_future (
181
+ self ._async_reader .commit_with_ack (mess )
182
+ )
172
183
173
184
def async_flush (self ) -> concurrent .futures .Future :
174
185
"""
0 commit comments