Last active
July 7, 2017 12:57
-
-
Save araraloren/c9f53c8aecaf1272765c70b25d3c347b to your computer and use it in GitHub Desktop.
A supply sample
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
#!/usr/bin/env perl6 | |
sub start-server(Supply $s, &operator --> Supply) { | |
supply { | |
sub server() { | |
whenever $s -> $msg { | |
if $msg ~~ Int || (try so $msg.Int) { | |
emit &operator($msg.Int); | |
} else { | |
die "Need an integer!"; | |
} | |
} | |
} | |
server(); | |
} | |
} | |
sub auto-restart(Supply $s --> Supply) { | |
supply { | |
sub auto() { | |
whenever $s -> $msg { | |
say "RESULT => " ~ $msg; | |
QUIT { | |
default { | |
.note; | |
"Ready to restart server".say; | |
auto(); | |
} | |
} | |
} | |
} | |
auto(); | |
} | |
} | |
my $supplier = Supplier.new; | |
my $supply = $supplier.Supply; | |
my $server = start-server($supply, -> $v { 2 * $v.Int }); | |
my $s = auto-restart($server); | |
$s.tap; | |
while (my $get = prompt("Input a number:")) { | |
$supplier.emit($get); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment