@@ -182,6 +182,46 @@ 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 get result right away in the case of success:
204
+ ``` c++
205
+ int rc = client.wait(conn, ping, WAIT_TIMEOUT, &result);
206
+ ```
207
+
208
+ Method ` waitAll ` waits for completion of all the given requests of a connection:
209
+ ``` c++
210
+ int rc = client.waitAll(conn, vector_of_futures, WAIT_TIMEOUT);
211
+ ```
212
+
213
+ Method ` waitCount ` waits until the given connection will complete any ` future_count ` requests:
214
+ ``` c++
215
+ int rc = client.waitCount(conn, future_count, WAIT_TIMEOUT);
216
+ ```
217
+
218
+ Method ` waitAny ` is different - it allows to poll all the connections simultaneously.
219
+ In the case of success, the function returns a connection that received a response.
220
+ In the case of internal error or when timeout is exceeded, returns ` std::nullopt ` .
221
+ ``` c++
222
+ std::optional<Connection<Buf, NetProvider>> conn_ready = client.waitAny(WAIT_TIMEOUT);
223
+ ```
224
+
185
225
### Receiving Responses
186
226
187
227
To get the response when it is ready, we can use ` Connection::getResponse() ` .
0 commit comments