📘 The closed method in Perl 6 channels

The Channel class also defines a method that checks on whether the channel is closed. This method is called closed. my $c = Channel.new; say “open” if !$c.closed; # is open  $c.close; say “closed” if $c.closed; # closed Despite the simplicity of using the method, it in fact returns not a simple Boolean value but … Continue reading “📘 The closed method in Perl 6 channels”

📘 The list method in Perl 6 channels

The list method accompanies the previously seen methods and returns everything that is left unread in the channel. my $c = Channel.new;  $c.send(5); $c.send(6);  $c.close; say $c.list; # (5 6) The method blocks the programme until the channel is open, thus it is wise to close it before calling the list method.

📘 The in and at methods in Perl 6 promises

The other two factory methods, Promise.in and Promise.at, create a promise, which will be kept after a given number of seconds or by a given time. For example: my $p = Promise.in(3); for 1..5 {     say $p.status;     sleep 1; } The programme prints the following lines. Planned Planned Planned Kept Kept That means … Continue reading “📘 The in and at methods in Perl 6 promises”

📘 Read and write in Perl 6 channels

In Perl 6, there is a predefined class Channel, which includes, among the others, the send and the receive methods. Here is the simplest example, where an integer number first is being sent to the channel $c and is then immediately read from it. my $c = Channel.new; $c.send(42); say $c.receive; # 42 A channel … Continue reading “📘 Read and write in Perl 6 channels”

📘 Transfer non-scalar objects through Perl 6 channels

Channels may also transfer both arrays and hashes and do it as easily as they work with scalars. Unlike Perl 5, an array will not be unfolded to a list of scalars but will be passed as a single unit. Thus, you may write the following code. my $c = Channel.new; my @a = (2, … Continue reading “📘 Transfer non-scalar objects through Perl 6 channels”

📘 Channels in Perl 6

Perl 6 includes a number of solutions for parallel and concurrent calculations. The great thing is that this is already built-in into the language and no external libraries are required. The idea of the channels is simple. You create a channel through which you can read and write. It is a kind of a pipe … Continue reading “📘 Channels in Perl 6”

📘 Basics of promises in Perl 6

The Promise.new constructor builds a new promise. The status of it can be read using the status method. Before any other actions are done with the promise, its status remains to be Planned. my $p = Promise.new; say $p.status; # Planned When the promise is kept, call the keep method to update the status to … Continue reading “📘 Basics of promises in Perl 6”