feat: add explicit Stdout.flush() and remove automatic flush on System.write()
Remove the automatic fflush(stdout) call from the write() function in vm.c, which was causing gratuitous performance overhead on every System.write() invocation. Introduce a new Stdout class with a foreign static flush() method that delegates to fflush(stdout), giving users explicit control over when output is flushed. Update the io module registration in modules.c to include the Stdout class and bump MAX_CLASSES_PER_MODULE from 5 to 6. Add documentation for Stdout in doc/site/modules/io/stdout.markdown, update the io index and template to list the new class, and add flush() usage notes to the Stdin readByte() and readLine() docs. Implement the stdoutFlush() foreign function in io.c.
This commit is contained in:
@@ -6,3 +6,4 @@ Provides access to operating system streams and the file system.
|
||||
* [File](file.html)
|
||||
* [Stat](stat.html)
|
||||
* [Stdin](stdin.html)
|
||||
* [Stdout](stdout.html)
|
||||
|
||||
@@ -29,9 +29,17 @@ been received.
|
||||
|
||||
Returns the byte value as a number or `null` if stdin is closed.
|
||||
|
||||
Note that output is not automatically flushed when calling this. If you want to
|
||||
display a prompt before reading input, you'll want to call `Stdout.flush()`
|
||||
after printing the prompt.
|
||||
|
||||
### **readLine**()
|
||||
|
||||
Reads one line of input from stdin. Blocks the current fiber until a full line
|
||||
of input has been received.
|
||||
|
||||
Returns the string of input or `null` if stdin is closed.
|
||||
|
||||
Note that output is not automatically flushed when calling this. If you want to
|
||||
display a prompt before reading input, you'll want to call `Stdout.flush()`
|
||||
after printing the prompt.
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
^title Stdout Class
|
||||
|
||||
The standard output stream.
|
||||
|
||||
## Static Methods
|
||||
|
||||
### **flush()**
|
||||
|
||||
Flushes all buffered data to the stream. Ensures any data written to stdout
|
||||
that is in the buffer gets written to the file or terminal that stdout is
|
||||
connected to.
|
||||
@@ -32,6 +32,7 @@
|
||||
<li><a href="file-flags.html">FileFlags</a></li>
|
||||
<li><a href="stat.html">Stat</a></li>
|
||||
<li><a href="stdin.html">Stdin</a></li>
|
||||
<li><a href="stdout.html">Stdout</a></li>
|
||||
</ul>
|
||||
</section>
|
||||
</nav>
|
||||
@@ -56,6 +57,7 @@
|
||||
<ul>
|
||||
<li><a href="stat.html">Stat</a></li>
|
||||
<li><a href="stdin.html">Stdin</a></li>
|
||||
<li><a href="stdout.html">Stdout</a></li>
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user