Skip to content

Instantly share code, notes, and snippets.

@robertlemmen
Created August 19, 2018 20:15
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 robertlemmen/9d08216be618674ce1d8d6cb48f4ec8e to your computer and use it in GitHub Desktop.
Save robertlemmen/9d08216be618674ce1d8d6cb48f4ec8e to your computer and use it in GitHub Desktop.
IO::Socket::Async is async, but not parallel
#!/usr/bin/env perl6
# start this and then run e.g. ab -n 100 -c 25 http://127.0.0.1:6060
# you can also try by hand with telnet or so
my $h = '0.0.0.0';
my $p = 6060;
say "starting tcp server on $h:$p";
my $server-socket = IO::Socket::Async.listen($h, $p);
my $done = Promise.new();
my $srv-tap = $server-socket.tap( -> $client-socket {
say "accepted connection in thread {$*THREAD.id}";
$client-socket.Supply(:bin).tap( -> $input {
say "input, handled in thread {$*THREAD.id}";
# XXX do something with it
},
done => {
say "connection lost";
});
});
await $done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment