Skip to content

Commit 5c1ceb5

Browse files
committed
readme: add a section about waiting for response
The new section covers all available ways of waiting for responses.
1 parent b47a9fd commit 5c1ceb5

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,46 @@ 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+
* 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+
185225
### Receiving Responses
186226

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

0 commit comments

Comments
 (0)