Skip to content

Commit

Permalink
feat(request): Updates request-multi to support scatter/gather operat…
Browse files Browse the repository at this point in the history
…ions

One of the uses of request-multi is to support a scatter/gather operation.
In these cases, you might not know how many requests you are going to
receive, so you can't set expected replies. Generally these wait until
timeout and then return the results. This commit adds the ability to
support all the different use cases for request-multi

Signed-off-by: Taylor Thomas <[email protected]>
  • Loading branch information
thomastaylor312 committed Jul 17, 2024
1 parent 20ddd68 commit 35582ed
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
20 changes: 16 additions & 4 deletions imports-request-reply.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ the request/reply operation will block until a message is received in response.<
<li><a name="method_request_options.set_timeout_ms.self"></a><code>self</code>: borrow&lt;<a href="#request_options"><a href="#request_options"><code>request-options</code></a></a>&gt;</li>
<li><a name="method_request_options.set_timeout_ms.timeout_ms"></a><code>timeout-ms</code>: <code>u32</code></li>
</ul>
<h4><a name="method_request_options.set_expected_replies"></a><code>[method]request-options.set-expected-replies: func</code></h4>
<p>The maximum number of replies to expect before returning. This only applies to
<a href="#request_multi"><code>request-multi</code></a> and is ignored otherwise. If the number of replies is not set and
timeout isn't set, then the operation will block until a message is received in
response (essentially the same behavior as <a href="#request"><code>request</code></a>).</p>
<h5>Params</h5>
<ul>
<li><a name="method_request_options.set_expected_replies.self"></a><code>self</code>: borrow&lt;<a href="#request_options"><a href="#request_options"><code>request-options</code></a></a>&gt;</li>
<li><a name="method_request_options.set_expected_replies.expected_replies"></a><code>expected-replies</code>: <code>u32</code></li>
</ul>
<h4><a name="request"></a><code>request: func</code></h4>
<p>Performs a blocking request/reply operation with an optional set of request options. This
returns only the first reply received or a timeout . If more than one reply is expected, then the
Expand All @@ -185,14 +195,16 @@ returns only the first reply received or a timeout . If more than one reply is e
</ul>
<h4><a name="request_multi"></a><code>request-multi: func</code></h4>
<p>Performs a blocking request/reply operation with an optional set of request options. This
returns all replies received up to the number of expected replies. It is recommended to use
a <a href="#request_options"><code>request-options</code></a> with the timeout set to ensure that the operation does not block
indefinitely.</p>
returns all replies received up until timeout or the configured set of expected replies. It
is recommended to use a <a href="#request_options"><code>request-options</code></a> with the timeout set to ensure that the operation
does not block indefinitely. Unlike request, this function should not return an error on
timeout and should instead return all of the replies received up to that point. This is to
faciliate use in scatter/gather operations where the number of expected replies is not
known.</p>
<h5>Params</h5>
<ul>
<li><a name="request_multi.c"></a><code>c</code>: borrow&lt;<a href="#client"><a href="#client"><code>client</code></a></a>&gt;</li>
<li><a name="request_multi.msg"></a><code>msg</code>: own&lt;<a href="#message"><a href="#message"><code>message</code></a></a>&gt;</li>
<li><a name="request_multi.expected_replies"></a><code>expected-replies</code>: <code>u32</code></li>
<li><a name="request_multi.opts"></a><code>opts</code>: option&lt;own&lt;<a href="#request_options"><a href="#request_options"><code>request-options</code></a></a>&gt;&gt;</li>
</ul>
<h5>Return values</h5>
Expand Down
17 changes: 13 additions & 4 deletions wit/request-reply.wit
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ interface request-reply {
/// The maximum amount of time to wait for a response. If the timeout value is not set, then
/// the request/reply operation will block until a message is received in response.
set-timeout-ms: func(timeout-ms: u32);

/// The maximum number of replies to expect before returning. This only applies to
/// `request-multi` and is ignored otherwise. If the number of replies is not set and
/// timeout isn't set, then the operation will block until a message is received in
/// response (essentially the same behavior as `request`).
set-expected-replies: func(expected-replies: u32);
}

/// Performs a blocking request/reply operation with an optional set of request options. This
Expand All @@ -22,10 +28,13 @@ interface request-reply {
request: func(c: borrow<client>, msg: message, opts: option<request-options>) -> result<message, error>;

/// Performs a blocking request/reply operation with an optional set of request options. This
/// returns all replies received up to the number of expected replies. It is recommended to use
/// a `request-options` with the timeout set to ensure that the operation does not block
/// indefinitely.
request-multi: func(c: borrow<client>, msg: message, expected-replies: u32, opts: option<request-options>) -> result<list<message>, error>;
/// returns all replies received up until timeout or the configured set of expected replies. It
/// is recommended to use a `request-options` with the timeout set to ensure that the operation
/// does not block indefinitely. Unlike request, this function should not return an error on
/// timeout and should instead return all of the replies received up to that point. This is to
/// faciliate use in scatter/gather operations where the number of expected replies is not
/// known.
request-multi: func(c: borrow<client>, msg: message, opts: option<request-options>) -> result<list<message>, error>;

/// Replies to the given message with the given response message. The details of which channel
/// the message is sent to is up to the implementation. This allows for reply to details to be
Expand Down

0 comments on commit 35582ed

Please sign in to comment.