Skip to content

Commit 90b25ee

Browse files
committed
readme: add a section about waiting for response
The new section covers all available ways of waiting for responses.
1 parent 07da2db commit 90b25ee

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

README.md

+39
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,45 @@ request is ready, `wait()` terminates. It also provides negative return code in
182182
case of system related fails (e.g. broken or time outed connection). If `wait()`
183183
returns 0, then response is received and expected to be parsed.
184184

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+
1. If `timeout > 0`, the connector blocks for `timeout` **milliseconds** or until
190+
all required responses are received.
191+
2. If `timeout == 0`, the connector decodes all available responsed and returns
192+
immediately.
193+
3. If `timeout == -1`, the connector blocks until required responses is received
194+
(basically, no timeout).
195+
196+
All the waiting functions (except for `waitAny`, its desctiption will be later)
197+
return 0 on success, -1 in the case of any internal error or when timeout is exceeded.
198+
199+
Method `wait` waits for one request, optional argument allows to get result right away
200+
in case of success:
201+
```c++
202+
int rc = client.wait(conn, ping, WAIT_TIMEOUT);
203+
int rc = client.wait(conn, ping, WAIT_TIMEOUT, &result);
204+
```
205+
206+
Method `waitAll` waits for all requests of a connection from the passed vector:
207+
```c++
208+
int rc = client.waitAll(conn, vector_of_futures, WAIT_TIMEOUT);
209+
```
210+
211+
Method `waitCount` waits until the given connection will receive responses to
212+
any `future_count` requests:
213+
```c++
214+
int rc = client.waitCount(conn, future_count, WAIT_TIMEOUT);
215+
```
216+
217+
Method `waitAny` is different - it allows to poll all the connections simultaneously.
218+
In the case of success, the function returns a connection that received a response.
219+
In the case of internal error or when timeout is exceeded, returns `std::nullopt`.
220+
```c++
221+
std::optional<Connection<Buf, NetProvider>> conn_ready = client.waitAny(WAIT_TIMEOUT);
222+
```
223+
185224
### Receiving Responses
186225

187226
To get the response when it is ready, we can use `Connection::getResponse()`.

0 commit comments

Comments
 (0)