@@ -182,6 +182,50 @@ 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. Time is measured against the monotonic clock.
191
+ * If ` timeout == 0 ` , the connector decodes all available responses 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 (for example,
198
+ when the underlying connection is closed) or when timeout is exceeded. In order
199
+ to differentiate between them, use ` Connection::hasError() ` method.
200
+
201
+ Method ` wait ` waits for one request:
202
+ ``` c++
203
+ int rc = client.wait(conn, ping, WAIT_TIMEOUT);
204
+ ```
205
+ An optional argument allows to obtain response right away in the case of success:
206
+ ``` c++
207
+ Response<Buf_t> response;
208
+ int rc = client.wait(conn, ping, WAIT_TIMEOUT, &response);
209
+ ```
210
+
211
+ Method ` waitAll ` waits for completion of all the given requests of a connection:
212
+ ``` c++
213
+ std::vector<rid_t > futures{ping1, ping2, call, replace};
214
+ int rc = client.waitAll(conn, futures, WAIT_TIMEOUT);
215
+ ```
216
+
217
+ Method `waitCount` waits until the given connection will complete any `future_count` requests:
218
+ ```c++
219
+ int rc = client.waitCount(conn, future_count, WAIT_TIMEOUT);
220
+ ```
221
+
222
+ Method ` waitAny ` is different - it allows to poll all the connections simultaneously.
223
+ In the case of success, the function returns a connection that received a response.
224
+ In the case of internal error or when timeout is exceeded, returns ` std::nullopt ` .
225
+ ``` c++
226
+ std::optional<Connection<Buf, NetProvider>> conn_ready = client.waitAny(WAIT_TIMEOUT);
227
+ ```
228
+
185
229
### Receiving Responses
186
230
187
231
To get the response when it is ready, we can use ` Connection::getResponse() ` .
0 commit comments