Skip to content

Commit

Permalink
IO::Socket::Async server example using heredoc
Browse files Browse the repository at this point in the history
and maybe more clearer for newcomers
  • Loading branch information
Jarkko Haapalainen committed Oct 25, 2017
1 parent 2222abe commit 5a49f8b
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions doc/Type/IO/Socket/Async.pod6
Expand Up @@ -15,23 +15,28 @@ http server that listens on port 3333:
=begin code :skip-test<IO>
react {
whenever IO::Socket::Async.listen('0.0.0.0', 3333) -> $conn {
whenever $conn.Supply.lines {
say .Str;
{ try $conn.print(.Str ~ "\n") } for
"HTTP/1.1 200 OK",
"Content-Type: text/html; charset=UTF-8",
"Content-Encoding: UTF-8",
"",
"<html><body>Hello World!</body></html>";
whenever $conn.Supply.lines -> $line {
$conn.print: qq:heredoc/END/;
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Content-Encoding: UTF-8
<html>
<body>
<h1>Hello World!</h1>
<p>{ $line }</p>
</body>
</html>
END
$conn.close;
}
CLOSE {
note „{now} connection closed“;
}
CATCH {
default {
say .^name, ': ', .Str;
say "handled in $?LINE";
}
}
CATCH { default { say .^name, ': ', .Str; say "handled in $?LINE"; } }
}
=end code
Expand Down

0 comments on commit 5a49f8b

Please sign in to comment.