See Original text in context
method Supply(Promise:)
Returns a Supply that will emit the result
of the Promise being Kept or quit
with the cause
if the Promise is Broken.
See Original text in context
method Supply(--> Supply) is nodal
First, it coerces the invocant to a list
by applying its .list
method, and then to a Supply.
See Original text in context
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 Supply
will quit
.
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.
See Original text in context
method Supply(Channel:)
This returns an on-demand
Supply that emits a value for every value received on the Channel. done
will be called on the Supply
when the Channel is closed.
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.
See Original text in context
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).
react
It is an error to create both binary and non-binary .Supply
. It is also an error to use both .Supply
and either stderr or stdout supplies.
See Original text in context
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 live
supplies.
See Original text in context
multi method Supply(IO::Handle: : = 65536)
Returns a Supply
that will emit the contents of the handle in chunks. The chunks will be Buf if the handle is in binary mode or, if it isn't, Str decoded using same encoding as IO::Handle.encoding
.
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"
See Original text in context
method Supply(IO::CatHandle: : = 65536 --> Supply)
Returns a Supply fed with either .read
, if the handle is in :$encoding
, 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 65536
).
(my = 'foo'.IO).spurt: 'foo';(my = 'bar'.IO).spurt: 'bar';react whenever IO::CatHandle.new(, ).Supply: :2size# OUTPUT: «foobar»react whenever IO::CatHandle.new(:bin, , ).Supply: :2size# OUTPUT: «Buf[uint8]:0x<66 6f>Buf[uint8]:0x<6f 62>Buf[uint8]:0x<61 72>»