method Supply

Documentation for method Supply assembled from the following types:

class Supplier

From Supplier

(Supplier) method Supply

method Supply(Supplier:D: --> 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 Channel

From Channel

(Channel) method Supply

Defined as:

method Supply(Channel:D:)

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 $c = Channel.new;
my Supply $s1 = $c.Supply;
my Supply $s2 = $c.Supply;
$s1.tap(-> $v { say "First $v" });
$s2.tap(-> $v { say "Second $v" });
^10 .map({ $c.send($_});
sleep 1;

Multiple calls to this method produce multiple instances of Supply, which compete over the values from the Channel.

class Promise

From Promise

(Promise) method Supply

method Supply(Promise:D:)

Returns a Supply that will emit the result of the Promise being Kept or quit with the cause if the Promise is Broken.

class Any

From Any

(Any) method Supply

Defined as:

method Supply(--> Supply:Dis nodal

First, it coerces the invocant to a list by applying its .list method, and then to a Supply.

class Proc::Async

From Proc::Async

(Proc::Async) method Supply

multi method Supply(Proc::Async:D: :$bin!)
multi method Supply(Proc::Async:D: :$enc:$translate-nl)

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 {
    with Proc::Async.new: «"$*EXECUTABLE" -e 'say 42; note 100'» {
        whenever .Supply { .print }  # OUTPUT: «42␤100␤» 
        whenever .start {}
    }
}

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 IO::CatHandle

From IO::CatHandle

(IO::CatHandle) method Supply

Defined as:

method Supply(IO::CatHandle:D: :$size = 65536 --> Supply:D)

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 $f1 = 'foo'.IO).spurt: 'foo';
(my $f2 = 'bar'.IO).spurt: 'bar';
react whenever IO::CatHandle.new($f1$f2).Supply: :2size {.say}
# OUTPUT: «fo␤ob␤ar␤» 
 
react whenever IO::CatHandle.new(:bin$f1$f2).Supply: :2size {.say}
# 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:D: :$size = 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: *.perl.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: *.perl.say;
# OUTPUT: 
# "I ♥ Perl" 
# " 6!\n" 

class IO::Socket::Async

From IO::Socket::Async

(IO::Socket::Async) method Supply

method Supply(:$bin:$buf = 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 Perl 6, 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.