Created
August 19, 2018 20:15
-
-
Save robertlemmen/9d08216be618674ce1d8d6cb48f4ec8e to your computer and use it in GitHub Desktop.
IO::Socket::Async is async, but not parallel
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 | |
# 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