Skip to content

Commit 1439bb9

Browse files
committed
Add forward
1 parent 324be89 commit 1439bb9

File tree

2 files changed

+93
-2
lines changed

2 files changed

+93
-2
lines changed

imports.md

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,14 @@ use the <code>subscribe</code> function to obtain a <a href="#pollable"><code>po
132132
for using <code>wasi:io/poll</code>.</p>
133133
<h4><a name="output_stream"><code>resource output-stream</code></a></h4>
134134
<p>An output bytestream.</p>
135-
<h2><a href="#output_stream"><code>output-stream</code></a>s are <em>non-blocking</em> to the extent practical on
135+
<p><a href="#output_stream"><code>output-stream</code></a>s are <em>non-blocking</em> to the extent practical on
136136
underlying platforms. Except where specified otherwise, I/O operations also
137137
always return promptly, after the number of bytes that can be written
138138
promptly, which could even be zero. To wait for the stream to be ready to
139139
accept data, the <code>subscribe</code> function to obtain a <a href="#pollable"><code>pollable</code></a> which can be
140-
polled for using <code>wasi:io/poll</code>.</h2>
140+
polled for using <code>wasi:io/poll</code>.</p>
141+
<h4><a name="future_forward_result"><code>resource future-forward-result</code></a></h4>
142+
<h2>Represents a future which may eventually return trailers, or an error.</h2>
141143
<h3>Functions</h3>
142144
<h4><a name="method_input_stream.read"><code>[method]input-stream.read: func</code></a></h4>
143145
<p>Perform a non-blocking read from the stream.</p>
@@ -418,3 +420,56 @@ is ready for reading, before performing the <code>splice</code>.</p>
418420
<ul>
419421
<li><a name="method_output_stream.blocking_splice.0"></a> result&lt;<code>u64</code>, <a href="#stream_error"><a href="#stream_error"><code>stream-error</code></a></a>&gt;</li>
420422
</ul>
423+
<h4><a name="forward"><code>forward: func</code></a></h4>
424+
<p>Continuously read all data from the input stream and write it to the
425+
output stream.</p>
426+
<p>Forwarding is done on a background task. The tasks runs until either
427+
stream closes or fails. After that, the streams are dropped and the
428+
returned future is resolved. Dropping the future before it has been
429+
resolved aborts the background task and drops the streams.</p>
430+
<p>The future resolves with the reason that caused the forwarding to terminate.
431+
In case one of the streams ended normally, this will be <a href="#stream_error.closed"><code>stream-error::closed</code></a>.</p>
432+
<p>This function requires exclusive access to the provided streams,
433+
yet it does not change the ownership structure of them. I.e. they remain
434+
children of their parent resources. If the parents place any lifetimes
435+
restrictions on their children, those continue to apply.</p>
436+
<h5>Params</h5>
437+
<ul>
438+
<li><a name="forward.src"><code>src</code></a>: own&lt;<a href="#input_stream"><a href="#input_stream"><code>input-stream</code></a></a>&gt;</li>
439+
<li><a name="forward.dst"><code>dst</code></a>: own&lt;<a href="#output_stream"><a href="#output_stream"><code>output-stream</code></a></a>&gt;</li>
440+
</ul>
441+
<h5>Return values</h5>
442+
<ul>
443+
<li><a name="forward.0"></a> own&lt;<a href="#future_forward_result"><a href="#future_forward_result"><code>future-forward-result</code></a></a>&gt;</li>
444+
</ul>
445+
<h4><a name="method_future_forward_result.subscribe"><code>[method]future-forward-result.subscribe: func</code></a></h4>
446+
<p>Returns a pollable which becomes ready when either the result is
447+
available. When this pollable is ready, the <code>get</code> method will return
448+
<code>some</code>.</p>
449+
<h5>Params</h5>
450+
<ul>
451+
<li><a name="method_future_forward_result.subscribe.self"><code>self</code></a>: borrow&lt;<a href="#future_forward_result"><a href="#future_forward_result"><code>future-forward-result</code></a></a>&gt;</li>
452+
</ul>
453+
<h5>Return values</h5>
454+
<ul>
455+
<li><a name="method_future_forward_result.subscribe.0"></a> own&lt;<a href="#pollable"><a href="#pollable"><code>pollable</code></a></a>&gt;</li>
456+
</ul>
457+
<h4><a name="method_future_forward_result.get"><code>[method]future-forward-result.get: func</code></a></h4>
458+
<p>Get the resolved value.</p>
459+
<p>Returns:</p>
460+
<ul>
461+
<li><code>none</code>: when the future hasn't resolved yet. Use <code>subscribe</code> to wait
462+
for its completion.</li>
463+
<li><code>some(error(_))</code>: when the future is resolved, but the result value
464+
has already been taken before.</li>
465+
<li><code>some(ok(value))</code>: when the future is ready with a value. This is
466+
returned only once.</li>
467+
</ul>
468+
<h5>Params</h5>
469+
<ul>
470+
<li><a name="method_future_forward_result.get.self"><code>self</code></a>: borrow&lt;<a href="#future_forward_result"><a href="#future_forward_result"><code>future-forward-result</code></a></a>&gt;</li>
471+
</ul>
472+
<h5>Return values</h5>
473+
<ul>
474+
<li><a name="method_future_forward_result.get.0"></a> option&lt;result&lt;<a href="#stream_error"><a href="#stream_error"><code>stream-error</code></a></a>&gt;&gt;</li>
475+
</ul>

wit/streams.wit

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,40 @@ interface streams {
259259
len: u64,
260260
) -> result<u64, stream-error>;
261261
}
262+
263+
/// Continuously read all data from the input stream and write it to the
264+
/// output stream.
265+
///
266+
/// Forwarding is done on a background task. The tasks runs until either
267+
/// stream closes or fails. After that, the streams are dropped and the
268+
/// returned future is resolved. Dropping the future before it has been
269+
/// resolved aborts the background task and drops the streams.
270+
///
271+
/// The future resolves with the reason that caused the forwarding to terminate.
272+
/// In case one of the streams ended normally, this will be `stream-error::closed`.
273+
///
274+
/// This function requires exclusive access to the provided streams,
275+
/// yet it does not change the ownership structure of them. I.e. they remain
276+
/// children of their parent resources. If the parents place any lifetimes
277+
/// restrictions on their children, those continue to apply.
278+
forward: func(src: input-stream, dst: output-stream) -> future-forward-result;
279+
280+
/// Represents a future which may eventually return trailers, or an error.
281+
resource future-forward-result {
282+
/// Returns a pollable which becomes ready when either the result is
283+
/// available. When this pollable is ready, the `get` method will return
284+
/// `some`.
285+
subscribe: func() -> pollable;
286+
287+
/// Get the resolved value.
288+
///
289+
/// Returns:
290+
/// - `none`: when the future hasn't resolved yet. Use `subscribe` to wait
291+
/// for its completion.
292+
/// - `some(error(_))`: when the future is resolved, but the result value
293+
/// has already been taken before.
294+
/// - `some(ok(value))`: when the future is ready with a value. This is
295+
/// returned only once.
296+
get: func() -> option<result<stream-error>>;
297+
}
262298
}

0 commit comments

Comments
 (0)