Skip to content

Instantly share code, notes, and snippets.

@jnthn

jnthn/x.p6 Secret

Created February 15, 2017 15:39
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 jnthn/a4b1dee678638041e791c63e4cd5c5c8 to your computer and use it in GitHub Desktop.
Save jnthn/a4b1dee678638041e791c63e4cd5c5c8 to your computer and use it in GitHub Desktop.
use v6.d.PREVIEW;
use Test;
my @closings;
sub make-supply() {
my $s = Supplier::Preserving.new;
my $done = False;
start {
until $done {
$s.emit: ++$
}
}
$s.Supply.on-close({ push @closings, 'x'; $done = True })
}
for ^10 {
my $s2 = make-supply;
my @received;
react {
whenever $s2 -> $n {
push @received, $n;
done if $n >= 5;
}
}
is @received, [1,2,3,4,5], "Received expected messages ($_)";
}
is @closings.join, 'xxxxxxxxxx', 'Close called as expected';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment