Documentation for method
Supply assembled from the following types:
method Supply(IO::CatHandle: : = 65536 --> Supply)
Returns a Supply fed with either
.read, if the handle is in binary mode, or with
.readchars, if it isn't, with reads of
:$size bytes or characters.
:$size defaults to an implementation-specific value (in Rakudo, the value of
$*DEFAULT-READ-ELEMS, which by default is set to
(my = 'foo'.IO).spurt: 'foo';(my = 'bar'.IO).spurt: 'bar';react whenever IO::CatHandle.new(, ).Supply: :2size# OUTPUT: «fo␤ob␤ar␤»react whenever IO::CatHandle.new(:bin, , ).Supply: :2size# OUTPUT: «Buf[uint8]:0x<66 6f>␤Buf[uint8]:0x<6f 62>␤Buf[uint8]:0x<61 72>␤»
multi method Supply(IO::Handle: : = 65536)
The size of the chunks is determined by the optional
:size named parameter and
65536 bytes in binary mode or
65536 characters in non-binary mode.
"foo".IO.open(:bin).Supply(:size<10>).tap: *.raku.say;# OUTPUT:# Buf[uint8].new(73,32,226,153,165,32,80,101,114,108)# Buf[uint8].new(32,54,33,10)"foo".IO.open.Supply(:size<10>).tap: *.raku.say;# OUTPUT:# "I ♥ Perl"# " 6!\n"
method Supply(:, : = buf8.new --> Supply)
Returns a Supply which can be tapped to obtain the data read from the connected IO::Socket::Async as it arrives. By default the data will be emitted as characters, but if the
:bin adverb is provided a Buf of bytes will be emitted instead, optionally in this case you can provide your own
Buf with the
:buf named parameter.
A UDP socket in character mode will treat each packet as a complete message and decode it. In the event of a decoding error, the
On the other hand, a TCP socket treats the incoming packets as part of a stream, and feeds the incoming bytes into a streaming decoder. It then emits whatever characters the decoder considers ready. Since strings work at grapheme level in Raku, this means that only known complete graphemes will be emitted. For example, if the UTF-8 encoding were being used and the last byte in the packet decoded to
a, this would not be emitted since the next packet may include a combining character that should form a single grapheme together with the
a. Control characters (such as
\n) always serve as grapheme boundaries, so any text-based protocols that use newlines or null bytes as terminators will not need special consideration. A TCP socket will also
quit upon a decoding error.
method Supply(--> Supply) is nodal
my = Channel.new;my Supply = .Supply;my Supply = .Supply;.tap(-> );.tap(-> );^10 .map();sleep 1;
Multiple calls to this method produce multiple instances of Supply, which compete over the values from the Channel.
method Supply(Supplier: --> Supply)
This creates a new
Supply object to which any values which are emitted on this supplier are passed. This is the factory for all
multi method Supply(Proc::Async: :!)multi method Supply(Proc::Async: :, :)
Returns a Supply of merged stdout and stderr streams. If
:$bin named argument is provided, the
Supply will be binary, producing Buf objects, otherwise, it will be in character mode, producing Str objects and
:$enc named argument can specify encoding to use. The
:$translate-nl option specifies whether new line endings should be translated for to match those used by the current operating system (e.g.
\r\n on Windows).