Skip to content

Commit 42b92bd

Browse files
authored
output-stream: clarify semantics of blocking-write-and-flush (#112)
* output-stream: clarify semantics of blocking-write-and-flush Closes #109 * generate md
1 parent 176892a commit 42b92bd

File tree

2 files changed

+18
-78
lines changed

2 files changed

+18
-78
lines changed

imports.md

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -267,25 +267,13 @@ the last call to check-write provided a permit.</p>
267267
<h4><a id="method_output_stream_blocking_write_and_flush"></a><code>[method]output-stream.blocking-write-and-flush: func</code></h4>
268268
<p>Perform a write of up to 4096 bytes, and then flush the stream. Block
269269
until all of these operations are complete, or an error occurs.</p>
270-
<p>This is a convenience wrapper around the use of <code>check-write</code>,
271-
<code>subscribe</code>, <code>write</code>, and <code>flush</code>, and is implemented with the
272-
following pseudo-code:</p>
273-
<pre><code class="language-text">let pollable = this.subscribe();
274-
while !contents.is_empty() {
275-
// Wait for the stream to become writable
276-
pollable.block();
277-
let Ok(n) = this.check-write(); // eliding error handling
278-
let len = min(n, contents.len());
279-
let (chunk, rest) = contents.split_at(len);
280-
this.write(chunk ); // eliding error handling
281-
contents = rest;
282-
}
283-
this.flush();
284-
// Wait for completion of `flush`
285-
pollable.block();
286-
// Check for any errors that arose during `flush`
287-
let _ = this.check-write(); // eliding error handling
288-
</code></pre>
270+
<p>Returns success when all of the contents written are successfully
271+
flushed to output. If an error occurs at any point before all
272+
contents are successfully flushed, that error is returned as soon as
273+
possible. If writing and flushing the complete contents causes the
274+
stream to become closed, this call should return success, and
275+
subsequent calls to check-write or other interfaces should return
276+
stream-error::closed.</p>
289277
<h5>Params</h5>
290278
<ul>
291279
<li><a id="method_output_stream_blocking_write_and_flush.self"></a><code>self</code>: borrow&lt;<a href="#output_stream"><a href="#output_stream"><code>output-stream</code></a></a>&gt;</li>
@@ -359,24 +347,8 @@ that should be written.</p>
359347
<p>Perform a write of up to 4096 zeroes, and then flush the stream.
360348
Block until all of these operations are complete, or an error
361349
occurs.</p>
362-
<p>This is a convenience wrapper around the use of <code>check-write</code>,
363-
<code>subscribe</code>, <code>write-zeroes</code>, and <code>flush</code>, and is implemented with
364-
the following pseudo-code:</p>
365-
<pre><code class="language-text">let pollable = this.subscribe();
366-
while num_zeroes != 0 {
367-
// Wait for the stream to become writable
368-
pollable.block();
369-
let Ok(n) = this.check-write(); // eliding error handling
370-
let len = min(n, num_zeroes);
371-
this.write-zeroes(len); // eliding error handling
372-
num_zeroes -= len;
373-
}
374-
this.flush();
375-
// Wait for completion of `flush`
376-
pollable.block();
377-
// Check for any errors that arose during `flush`
378-
let _ = this.check-write(); // eliding error handling
379-
</code></pre>
350+
<p>Functionality is equivelant to <code>blocking-write-and-flush</code> with
351+
contents given as a list of len containing only zeroes.</p>
380352
<h5>Params</h5>
381353
<ul>
382354
<li><a id="method_output_stream_blocking_write_zeroes_and_flush.self"></a><code>self</code>: borrow&lt;<a href="#output_stream"><a href="#output_stream"><code>output-stream</code></a></a>&gt;</li>

wit/streams.wit

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -154,27 +154,13 @@ interface streams {
154154
/// Perform a write of up to 4096 bytes, and then flush the stream. Block
155155
/// until all of these operations are complete, or an error occurs.
156156
///
157-
/// This is a convenience wrapper around the use of `check-write`,
158-
/// `subscribe`, `write`, and `flush`, and is implemented with the
159-
/// following pseudo-code:
160-
///
161-
/// ```text
162-
/// let pollable = this.subscribe();
163-
/// while !contents.is_empty() {
164-
/// // Wait for the stream to become writable
165-
/// pollable.block();
166-
/// let Ok(n) = this.check-write(); // eliding error handling
167-
/// let len = min(n, contents.len());
168-
/// let (chunk, rest) = contents.split_at(len);
169-
/// this.write(chunk ); // eliding error handling
170-
/// contents = rest;
171-
/// }
172-
/// this.flush();
173-
/// // Wait for completion of `flush`
174-
/// pollable.block();
175-
/// // Check for any errors that arose during `flush`
176-
/// let _ = this.check-write(); // eliding error handling
177-
/// ```
157+
/// Returns success when all of the contents written are successfully
158+
/// flushed to output. If an error occurs at any point before all
159+
/// contents are successfully flushed, that error is returned as soon as
160+
/// possible. If writing and flushing the complete contents causes the
161+
/// stream to become closed, this call should return success, and
162+
/// subsequent calls to check-write or other interfaces should return
163+
/// stream-error::closed.
178164
@since(version = 0.2.0)
179165
blocking-write-and-flush: func(
180166
contents: list<u8>
@@ -227,26 +213,8 @@ interface streams {
227213
/// Block until all of these operations are complete, or an error
228214
/// occurs.
229215
///
230-
/// This is a convenience wrapper around the use of `check-write`,
231-
/// `subscribe`, `write-zeroes`, and `flush`, and is implemented with
232-
/// the following pseudo-code:
233-
///
234-
/// ```text
235-
/// let pollable = this.subscribe();
236-
/// while num_zeroes != 0 {
237-
/// // Wait for the stream to become writable
238-
/// pollable.block();
239-
/// let Ok(n) = this.check-write(); // eliding error handling
240-
/// let len = min(n, num_zeroes);
241-
/// this.write-zeroes(len); // eliding error handling
242-
/// num_zeroes -= len;
243-
/// }
244-
/// this.flush();
245-
/// // Wait for completion of `flush`
246-
/// pollable.block();
247-
/// // Check for any errors that arose during `flush`
248-
/// let _ = this.check-write(); // eliding error handling
249-
/// ```
216+
/// Functionality is equivelant to `blocking-write-and-flush` with
217+
/// contents given as a list of len containing only zeroes.
250218
@since(version = 0.2.0)
251219
blocking-write-zeroes-and-flush: func(
252220
/// The number of zero-bytes to write

0 commit comments

Comments
 (0)