Skip to content

Instantly share code, notes, and snippets.

@japhb
Created February 4, 2017 05:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save japhb/40772099ed24e20ec2c37c06f434594b to your computer and use it in GitHub Desktop.
Save japhb/40772099ed24e20ec2c37c06f434594b to your computer and use it in GitHub Desktop.
infinite supply {} + react {} = hang
# 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