Skip to content

Commit 52a793b

Browse files
committed
Document handle buffering
- :buffer remains under the hood, deprecated for 3 releases - :buffer is now :out-buffer, tweaking output buffer - :in-buffer lets tweak input buffer Impl: rakudo/rakudo@f9c10c2145 rakudo/rakudo@3fcd74abf0 Spec: Raku/roast@1a7b5f6130 Raku/roast@a99c1d5ae1
1 parent f7eefbd commit 52a793b

File tree

2 files changed

+42
-19
lines changed

2 files changed

+42
-19
lines changed

doc/Language/5to6-perlvar.pod6

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,9 @@ C<$*OUT.nl-out>.
462462
463463
=item $|
464464
465-
No current alternative exists as there's no buffering. Experimental support via C<:buffer>
466-
parameter to L<open> is currently in the works.
465+
No global alternative available. TTY handles are unbuffered by default, for
466+
otheres, set L<out-buffer> to zero or use C<:!out-buffer> with L<open> on a
467+
specific L<IO::Handle>.
467468
468469
=item ${^LAST_FH}
469470

doc/Type/IO/Handle.pod6

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ method open(IO::Handle:D:
1818
Str :$mode,
1919
:$r, :$w, :$a, :$x, :$update, :$rw, :$rx, :$ra,
2020
:$create, :$append, :$truncate, :$exclusive,
21-
:$buffer
21+
:$out-buffer, :$in-buffer
2222
--> IO::Handle:D
2323
)
2424
@@ -84,24 +84,15 @@ modes in this case will result in exception being thrown.
8484
8585
In B<6.d> language, path C<'-'> has no special meaning.
8686
87-
Passing the C<:buffer> named argument enables output buffering for the handle,
88-
while C<:!buffer> disables it. The output buffer size is implementation defined.
89-
Passing an C<Int> allows the buffer size to be specified (the units are bytes);
90-
C<:0buffer> is equivalent to disabling output buffering. If a value other than
91-
an C<Int> or a C<Bool> is passed, it will be coerced into an C<Int>.
92-
93-
When no output buffering options are specified, then the default will be
94-
C<:buffer> for non-TTY handles, and C<:!buffer> for TTY handles. A Perl 6
95-
implementation is required to flush the output buffers of C<< PROCESS::<$OUT> >>
96-
and C<< PROCESS::<$ERR> >> at program exit. All other handles should be
97-
explicitly closed to ensure that output buffers are flushed as part of the
98-
closing.
87+
The C<:out-buffer> and C<:in-buffer> control input and output buffering
88+
and by default behave as if values were C<Nil>.
89+
See methods L<out-buffer> and L<in-buffer> for details.
9990
10091
B<Note:> unlike some other languages, Perl 6 does not use reference counting,
101-
and so B<the file handles are NOT flushed or closed when they go out of scope
102-
nor reliably at program exit>. While they I<will> get closed when garbage
103-
collected, garbage collection isn't guaranteed to get run. This means B<you must>
104-
use an explicit C<close> on handles opened for writing, to avoid data loss, and
92+
and so B<the file handles are NOT flushed or closed when they go out of scope>.
93+
While they I<will> get closed when garbage collected, garbage collection isn't
94+
guaranteed to get run. This means I<you should> use an explicit C<close> on
95+
handles opened for writing, to avoid data loss, and
10596
an explicit C<close> is I<recommended> on handles opened for reading as well, so
10697
that your program does not open too many files at the same time, triggering
10798
exceptions on further C<open> calls.
@@ -488,6 +479,37 @@ my $fh = open 'path/to/file', :w;
488479
$fh.printf: "The value is %d\n", 32;
489480
$fh.close;
490481
482+
=head2 method out-buffer
483+
484+
Defined as:
485+
486+
method out-buffer(--> Int:D) is rw
487+
488+
Controls output buffering and can be set via an argument to L<open>. Takes
489+
an C<int> as the size of the buffer to use (zero is acceptable). Can take
490+
a L<Bool>: C<True> means to use default, implementation-defined buffer size;
491+
C<False> means to disable buffering (equivalent to using C<0> as buffer size).
492+
493+
Lastly, can take a C<Nil> to enable TTY-based buffering control: if
494+
the handle L<is a TTY|/routine/t>, the buffering is disabled, otherwise,
495+
default, implementation-defined buffer size is used.
496+
497+
=head2 method in-buffer
498+
499+
Defined as:
500+
501+
method in-buffer(--> Int:D) is rw
502+
503+
Controls input buffering and can be set via an argument to L<open>.
504+
Implementations may do partial or no input buffering on
505+
L<binary|/routine/encoding> handles.
506+
507+
Takes an C<int> as the size of the buffer to use (zero is acceptable). Can
508+
also take a L<Bool>: C<True> means to use default, implementation-defined buffer
509+
size; C<False> means to disable buffering (equivalent to using C<0> as buffer
510+
size). C<Nil> is also accepted and means to use default, implementation-defined
511+
buffer size
512+
491513
=head2 method put
492514
493515
Defined as:

0 commit comments

Comments
 (0)