Skip to content

Instantly share code, notes, and snippets.

Created October 6, 2017 00:50
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 anonymous/e2f9cc4405ab9086472ddeb3771aef15 to your computer and use it in GitHub Desktop.
Save anonymous/e2f9cc4405ab9086472ddeb3771aef15 to your computer and use it in GitHub Desktop.
[jdv@new-host-2]$ cat t/01-basic.t
use v6.d.PREVIEW;
my $p_reactor = Promise.new;
class Server {
has $.host is rw = '0.0.0.0';
has $.port is rw = 5000;
has %.conns{IO::Socket::Async};
method start {
supply {
whenever IO::Socket::Async.listen($.host, $.port) -> $c-conn {
%.conns{$c-conn}<established> = Promise.new;
emit $c-conn;
%.conns{$c-conn}<msgs-supplier> = Supplier.new;
%.conns{$c-conn}<msgs>
= %.conns{$c-conn}<msgs-supplier>.Supply;
$c-conn.Supply.lines.tap({
%.conns{$c-conn}<msgs-supplier>.emit: $_ });
}
}
}
}
class Reactor {
method start ($msgs-in) {
start {
react whenever $msgs-in -> $msg-in {
say "before";
say qqx{echo foo};
say "after";
$p_reactor.keep;
}
}
}
}
start {
my $server = Server.new;
react whenever $server.start -> $c-conn {
start {
Reactor.new.start($server.conns{$c-conn}<msgs-supplier>.Supply);
}
}
}
sleep 1;
my $c = await IO::Socket::Async.connect('0.0.0.0', 5000);
await $c.print("foo\n");
await $p_reactor;
[jdv@new-host-2]$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment