A friend recently showed me a cool program in elixir to demonstrate message passing -- two threads count by passsing ascending numbers back and forth. A quick search turns up a handful of examples.

I decided to implement this in Perl 6. Here's what I came up with →

$ping and $pong are each a Channel. The subroutines ping and pong receive from their corresponding channels and send to the other one.

If you run this, you'll see the numbers from one to five.

ping 1 (thread #3) pong 2 (thread #4) ping 3 (thread #3) pong 4 (thread #4) ping 5 (thread #3)