Documentation for method Supply
assembled from the following pages:
Class: Supplier §
From Supplier
(Supplier) method Supply §
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.
Class: Any §
From Any
(Any) method Supply §
Defined as:
method Supply(--> Supply) is nodal
First, it coerces the invocant to a list
by applying its .list
method, and then to a Supply.
Class: Promise §
From Promise
(Promise) method Supply §
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.
Class: IO::CatHandle §
From IO::CatHandle
(IO::CatHandle) method Supply §
Defined as:
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 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>»
Class: IO::Handle §
From IO::Handle
(IO::Handle) method Supply §
Defined as:
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"
Class: IO::Socket::Async §
From IO::Socket::Async
(IO::Socket::Async) method Supply §
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.
Class: Proc::Async §
From Proc::Async
(Proc::Async) method Supply §
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.
Class: Channel §
From Channel
(Channel) method Supply §
Defined as:
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.