react (statement prefix) react

Documentation for react (statement prefix) react assembled from the following types:

language documentation Statement prefixes

From Statement prefixes

(Statement prefixes) react (statement prefix) react

react can be used in concurrent programs to create blocks of code that run whenever some event occurs. It works with blocks, and also as a statement prefix.

my Channel $KXGA .= new;
for ^100 {
    $KXGA.send( (100000..200000).pick );
}
 
my @sums = ( start react whenever $KXGA -> $number {
    say "In thread "$*THREAD.id;
    say "→ ", (^$number).sum;
} ) for ^10;
 
start { sleep 10$KXGA.close(); }
 
await @sums;

In this case react prefixes whenever, which makes a long sum with every number read from a channel.