Help with promises, supplies and channels.
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
Re: Help with promises, supplies and channels.
No problems so far. say $*VM; #add as last line, returns: moar (2021.06) On Tue, Apr 5, 2022 at 11:06 AM David Emanuel da Costa Santiago < deman...@gmail.com> wrote: > 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 >
Re: Help with promises, supplies and channels.
Hi William, when it fails or hangs it doesn't print the last line. Please check attached file for output of the stack. Since the failures are random, it's easier to invoke it in a loop: bash$ for i in $(seq 100); do raku test.raku; done If nothing is wrong with the code, i'll open a bug in the github. Regards, David Santiago Às 21:37 de 05/04/22, William Michels escreveu: No problems so far. say $*VM; #add as last line, returns: moar (2021.06) On Tue, Apr 5, 2022 at 11:06 AM David Emanuel da Costa Santiago mailto:deman...@gmail.com>> wrote: 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 demanuel@archlinux ~ [SIGINT]> raku test.raku 2 5 Data: 5.2 No exception handler located for catch at SETTING::src/core.c/Exception.pm6:62 (/usr/share/perl6/runtime/CORE.c.setting.moarvm:throw) from SETTING::src/core.c/Failure.pm6:63 (/usr/share/perl6/runtime/CORE.c.setting.moarvm:throw) from SETTING::src/core.c/Failure.pm6:125 (/usr/share/perl6/runtime/CORE.c.setting.moarvm:CALL-ME) from SETTING::src/core.c/Rakudo/Supply.pm6:118 (/usr/share/perl6/runtime/CORE.c.setting.moarvm:teardown) from SETTING::src/core.c/Rakudo/Supply.pm6:133 (/usr/share/perl6/runtime/CORE.c.setting.moarvm:run-done) from :1 (/usr/share/perl6/runtime/CORE.c.setting.moarvm:) from SETTING::src/core.c/control.pm6:20 (/usr/share/perl6/runtime/CORE.c.setting.moarvm:THROW-NIL) from SETTING::src/core.c/control.pm6:236 (/usr/share/perl6/runtime/CORE.c.setting.moarvm:done) from SETTING::src/core.c/Channel.pm6:162 (/usr/share/perl6/runtime/CORE.c.setting.moarvm:) from SETTING::src/core.c/Rakudo/Supply.pm6:233 (/usr/share/perl6/runtime/CORE.c.setting.moarvm:) from SETTING::src/core.c/Rakudo/Supply.pm6:244 (/usr/share/perl6/runtime/CORE.c.setting.moarvm:) from SETTING::src/core.c/Lock/Async.pm6:204 (/usr/share/perl6/runtime/CORE.c.setting.moarvm:run-under-recursion-list) from SETTING::src/core.c/Lock/Async.pm6:183 (/usr/share/perl6/runtime/CORE.c.setting.moarvm:run-with-updated-recursion-list) from SETTING::src/core.c/Lock/Async.pm6:146 (/usr/share/perl6/runtime/CORE.c.setting.moarvm:protect-or-queue-on-recursion) from SETTING::src/core.c/Rakudo/Supply.pm6:242 (/usr/share/perl6/runtime/CORE.c.setting.moarvm:run-supply-code) from SETTING::src/core.c/Rakudo/Supply.pm6:232 (/usr/share/perl6/runtime/CORE.c.setting.moarvm:tap) from SETTING::src/core.c/Supply.pm6:94 (/usr/share/perl6/runtime/CORE.c.setting.moarvm:tap) from SETTING::src/core.c/Rakudo/Supply.pm6:178 (/usr/share/perl6/runtime/CORE.c.setting.moarvm:) from SETTING::src/core.c/Rakudo/Supply.pm6:23 (/usr/share/perl6/runtime/CORE.c.setting.moarvm:) from SETTING::src/core.c/Rakudo/Supply.pm6:267 (/usr/share/perl6/runtime/CORE.c.setting.moarvm:) from SETTING::src/core.c/Rakudo/Supply.pm6:266 (/usr/share/perl6/runtime/CORE.c.setting.moarvm:) from SETTING::src/core.c/Rakudo/Supply.pm6:263 (/usr/share/perl6/runtime/CORE.c.setting.moarvm:) from SETTING::src/core.c/Rakudo/Supply.pm6:261 (/usr/share/perl6/runtime/CORE.c.setting.moarvm:run-add-whenever-awaits) from SETTING::src/core.c/Rakudo/Supply.pm6:256 (/usr/share/perl6/runtime/CORE.c.setting.moarvm:run-supply-code) from SETTING::src/core.c/Rakudo/Supply.pm6:232 (/usr/share/perl6/runtime/CORE.c.setting.moarvm:tap) from SETTING::src/core.c/Supply.pm6:94 (/usr/share/perl6/runtime/CORE.c.setting.moarvm:tap) from SETTING::src/core.d/await.pm6:70 (/usr/share/perl6/runtime/CORE.d.setting.moarvm:subscribe-awaiter) from SETTING::src/core.c/ThreadPoolScheduler.pm6:64 (/usr/share/perl6/runtime/CORE.c.setting.moarvm:) from SETTING::src/core.c/ThreadPoolScheduler.pm6:242 (/usr/share/perl6/runtime/CORE.c.setting.moarvm:run-one) from SETTING::src/core.c/ThreadPoolScheduler.pm6:284 (/usr/share/perl6/runtime/CORE.c.setting.moarvm:) from SE
Re: Help with promises, supplies and channels.
Thanks for the bash loop. I'm seeing a few hangs, also some errors returned saying: "Unhandled exception in code scheduled on thread 4" (MacOS 11.11) On Tue, Apr 5, 2022 at 12:47 PM David Emanuel da Costa Santiago < deman...@gmail.com> wrote: > > Hi William, > > when it fails or hangs it doesn't print the last line. > > Please check attached file for output of the stack. > > Since the failures are random, it's easier to invoke it in a loop: > > bash$ for i in $(seq 100); do raku test.raku; done > > If nothing is wrong with the code, i'll open a bug in the github. > > Regards, > David Santiago > > > Às 21:37 de 05/04/22, William Michels escreveu: > > No problems so far. > > > > say $*VM; #add as last line, returns: > > moar (2021.06) > > > > On Tue, Apr 5, 2022 at 11:06 AM David Emanuel da Costa Santiago > > mailto:deman...@gmail.com>> wrote: > > > > 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 > >