@@ -182,6 +182,48 @@ request is ready, `wait()` terminates. It also provides negative return code in
182
182
case of system related fails (e.g. broken or time outed connection). If ` wait() `
183
183
returns 0, then response is received and expected to be parsed.
184
184
185
+ ### Waiting for Responses
186
+
187
+ The connector provides several wait methods. All methods accept an integer ` timeout `
188
+ argument with the following semantics:
189
+ * If ` timeout > 0 ` , the connector blocks for ` timeout ` ** milliseconds** or until
190
+ all required responses are received.
191
+ * If ` timeout == 0 ` , the connector decodes all available responsed and returns
192
+ immediately.
193
+ * If ` timeout == -1 ` , the connector blocks until required responses are received
194
+ (basically, no timeout).
195
+
196
+ All the waiting functions (except for ` waitAny ` , its description will be later)
197
+ return ` 0 ` on success and ` -1 ` in the case of any internal error or when timeout is exceeded.
198
+
199
+ Method ` wait ` waits for one request:
200
+ ``` c++
201
+ int rc = client.wait(conn, ping, WAIT_TIMEOUT);
202
+ ```
203
+ An optional argument allows to obtain response right away in the case of success:
204
+ ``` c++
205
+ Response<Buf_t> response;
206
+ int rc = client.wait(conn, ping, WAIT_TIMEOUT, &response);
207
+ ```
208
+
209
+ Method ` waitAll ` waits for completion of all the given requests of a connection:
210
+ ``` c++
211
+ std::vector<rid_t > futures{ping1, ping2, call, replace};
212
+ int rc = client.waitAll(conn, futures, WAIT_TIMEOUT);
213
+ ```
214
+
215
+ Method `waitCount` waits until the given connection will complete any `future_count` requests:
216
+ ```c++
217
+ int rc = client.waitCount(conn, future_count, WAIT_TIMEOUT);
218
+ ```
219
+
220
+ Method ` waitAny ` is different - it allows to poll all the connections simultaneously.
221
+ In the case of success, the function returns a connection that received a response.
222
+ In the case of internal error or when timeout is exceeded, returns ` std::nullopt ` .
223
+ ``` c++
224
+ std::optional<Connection<Buf, NetProvider>> conn_ready = client.waitAny(WAIT_TIMEOUT);
225
+ ```
226
+
185
227
### Receiving Responses
186
228
187
229
To get the response when it is ready, we can use ` Connection::getResponse() ` .
0 commit comments