Skip to content

Commit 18f1288

Browse files
committed
fix: add outgoing-value.finish
Without an explicit `outgoing-value.finish`, the host may not know when the data stream has finished and when to stop writing. Additionally, this allows for errors to be communicated to the guest, which may have happened asynchronously Signed-off-by: Roman Volosatovs <[email protected]>
1 parent 6387153 commit 18f1288

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

imports.md

+20
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,13 @@ Soon: switch to <code>resource incoming-value { ... }</code></li>
521521
<li><a name="static_outgoing_value.new_outgoing_value.0"></a> own&lt;<a href="#outgoing_value"><a href="#outgoing_value"><code>outgoing-value</code></a></a>&gt;</li>
522522
</ul>
523523
<h4><a name="method_outgoing_value.outgoing_value_write_body"></a><code>[method]outgoing-value.outgoing-value-write-body: func</code></h4>
524+
<p>Returns a stream for writing the value contents.</p>
525+
<p>The returned <a href="#output_stream"><code>output-stream</code></a> is a child resource: it must be dropped
526+
before the parent <a href="#outgoing_value"><code>outgoing-value</code></a> resource is dropped (or finished),
527+
otherwise the <a href="#outgoing_value"><code>outgoing-value</code></a> drop or <code>finish</code> will trap.</p>
528+
<p>Returns success on the first call: the <a href="#output_stream"><code>output-stream</code></a> resource for
529+
this <a href="#outgoing_value"><code>outgoing-value</code></a> may be retrieved at most once. Subsequent calls
530+
will return error.</p>
524531
<h5>Params</h5>
525532
<ul>
526533
<li><a name="method_outgoing_value.outgoing_value_write_body.self"></a><code>self</code>: borrow&lt;<a href="#outgoing_value"><a href="#outgoing_value"><code>outgoing-value</code></a></a>&gt;</li>
@@ -529,6 +536,19 @@ Soon: switch to <code>resource incoming-value { ... }</code></li>
529536
<ul>
530537
<li><a name="method_outgoing_value.outgoing_value_write_body.0"></a> result&lt;own&lt;<a href="#output_stream"><a href="#output_stream"><code>output-stream</code></a></a>&gt;&gt;</li>
531538
</ul>
539+
<h4><a name="static_outgoing_value.finish"></a><code>[static]outgoing-value.finish: func</code></h4>
540+
<p>Finalize an outgoing value. This must be
541+
called to signal that the outgoing value is complete. If the <a href="#outgoing_value"><code>outgoing-value</code></a>
542+
is dropped without calling <code>outgoing-value.finalize</code>, the implementation
543+
should treat the value as corrupted.</p>
544+
<h5>Params</h5>
545+
<ul>
546+
<li><a name="static_outgoing_value.finish.this"></a><code>this</code>: own&lt;<a href="#outgoing_value"><a href="#outgoing_value"><code>outgoing-value</code></a></a>&gt;</li>
547+
</ul>
548+
<h5>Return values</h5>
549+
<ul>
550+
<li><a name="static_outgoing_value.finish.0"></a> result&lt;_, <a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li>
551+
</ul>
532552
<h4><a name="static_incoming_value.incoming_value_consume_sync"></a><code>[static]incoming-value.incoming-value-consume-sync: func</code></h4>
533553
<h5>Params</h5>
534554
<ul>

wit/types.wit

+16
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,23 @@ interface types {
5252
// Soon: switch to `resource value { ... }`
5353
resource outgoing-value {
5454
new-outgoing-value: static func() -> outgoing-value;
55+
56+
/// Returns a stream for writing the value contents.
57+
///
58+
/// The returned `output-stream` is a child resource: it must be dropped
59+
/// before the parent `outgoing-value` resource is dropped (or finished),
60+
/// otherwise the `outgoing-value` drop or `finish` will trap.
61+
///
62+
/// Returns success on the first call: the `output-stream` resource for
63+
/// this `outgoing-value` may be retrieved at most once. Subsequent calls
64+
/// will return error.
5565
outgoing-value-write-body: func() -> result<output-stream>;
66+
67+
/// Finalize an outgoing value. This must be
68+
/// called to signal that the outgoing value is complete. If the `outgoing-value`
69+
/// is dropped without calling `outgoing-value.finalize`, the implementation
70+
/// should treat the value as corrupted.
71+
finish: static func(this: outgoing-value) -> result<_, error>;
5672
}
5773

5874
/// A incoming-value is a wrapper around a value. It provides a way to read the value

0 commit comments

Comments
 (0)