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

Reply via email to