Course of Raku / Functional, concurrent, reactive, and web programming / Concurrent programming / Channels / Exercises / Receive a value

Solution: Receive a value

Here is a possible solution to the task.

Code

my $c = Channel.new;
$c.send('a');
$c.send('b');
say $c.receive;

🦋 You can find the source code in the file channel-receive.raku.

Output

a

Comments

  1. A channel returns values in the order they were sent.

  2. 'a' was sent first, so the first .receive returns it.

Course navigation

Receive a value   |   Sum a channel