-
-
Save japhb/40772099ed24e20ec2c37c06f434594b to your computer and use it in GitHub Desktop.
infinite supply {} + react {} = hang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use most advanced version of await/react/etc. | |
use v6.d.PREVIEW; | |
# Externally stoppable infinite supply | |
sub make-supply() { | |
my $done = False; | |
supply { | |
until $done { | |
say "Emitting ..."; | |
emit(++$); | |
} | |
} does role { method done { $done = True } } | |
} | |
# This works as expected, emit and receive paired, and ends after 5 | |
say "USING .act"; | |
my $s1 = make-supply; | |
$s1.act: -> $n { | |
say "Received $n"; | |
$s1.done if $n >= 5; | |
} | |
# This appears to try to exhaust the supply *before* receiving anything | |
say "\nUSING react"; | |
my $s2 = make-supply; | |
react { | |
whenever $s2 -> $n { | |
say "Received $n"; | |
$s1.done if $n >= 5; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment