Skip to content

Commit d8d82f7

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

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

README.md

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

189+
### Waiting for Responses
190+
191+
The connector provides several wait methods. All methods accept an integer `timeout`
192+
argument with the following semantics:
193+
* If `timeout > 0`, the connector blocks for `timeout` **milliseconds** or until
194+
all required responses are received. Time is measured against the monotonic clock.
195+
* If `timeout == 0`, the connector decodes all available responses and returns
196+
immediately.
197+
* If `timeout == -1`, the connector blocks until required responses are received
198+
(basically, no timeout).
199+
200+
All the waiting functions (except for `waitAny`, its description will be later)
201+
return `0` on success and `-1` in the case of any internal error (for example,
202+
when the underlying connection is closed) or when timeout is exceeded.
203+
See [this section](#error-handling) for error handling details.
204+
205+
Method `wait` waits for one request:
206+
```c++
207+
int rc = client.wait(conn, ping, WAIT_TIMEOUT);
208+
```
209+
An optional argument allows to obtain response right away in the case of success:
210+
```c++
211+
Response<Buf_t> response;
212+
int rc = client.wait(conn, ping, WAIT_TIMEOUT, &response);
213+
```
214+
215+
Method `waitAll` waits for completion of all the given requests of a connection:
216+
```c++
217+
std::vector<rid_t> futures{ping1, ping2, call, replace};
218+
int rc = client.waitAll(conn, futures, WAIT_TIMEOUT);
219+
```
220+
221+
Method `waitCount` waits until the given connection will complete any `future_count` requests:
222+
```c++
223+
int rc = client.waitCount(conn, future_count, WAIT_TIMEOUT);
224+
```
225+
226+
Method `waitAny` is different - it allows to poll all the connections simultaneously.
227+
In the case of success, the function returns a connection that received a response.
228+
In the case of internal error or when timeout is exceeded, returns `std::nullopt`.
229+
See [this section](#error-handling) for error handling details.
230+
```c++
231+
std::optional<Connection<Buf, NetProvider>> conn_ready = client.waitAny(WAIT_TIMEOUT);
232+
```
233+
189234
### Receiving Responses
190235

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

0 commit comments

Comments
 (0)