develooper Front page | perl.perl6.users | Postings from April 2022

Help with promises, supplies and channels.

Thread Next
From:
David Emanuel da Costa Santiago
Date:
April 5, 2022 18:06
Subject:
Help with promises, supplies and channels.
Message ID:
a6fb0de9-f524-4c21-77ef-f4a07a06150a@gmail.com
Hi,



I'm trying to learn about promises, supplies and channels. So i made 
this code:

"""

my $p1 = Supply.interval(5);
my $p2 = Supply.interval(2);
my Channel $ch = Channel.new;

my $prom = start react {
     whenever $p1 -> $interval {
         say "5";
     }

     whenever $p2 -> $interval {
         say 2;
     }

     whenever $ch.closed {
         done;
     }

     whenever $ch -> $data {
         say "Data: $data";
     }
}

my $prom2 = start react {
     whenever $p1 -> $interval {
         $ch.send("5.2");
         $ch.close;
     }
     whenever $ch.closed {
         done;
     }
}

my @proms = ($prom, $prom2);
await Promise.allof(@proms);

"""



I don't see anything wrong with this but most of the times runs fine, 
sometimes hangs, sometimes throw exception. Am i doing something that i 
shouldn't be doing?

$ raku --version
Welcome to Rakudo™ v2022.03-130-g8f7cc0847.
Implementing the Raku® Programming Language v6.d.
Built on MoarVM version 2022.03-13-ga3476e286.



Regards,
David Santiago

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About