Skip to content

Instantly share code, notes, and snippets.

@ufobat
Created October 16, 2017 12: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 ufobat/b165a66b1e3ab3228d1d0622fda20c9e to your computer and use it in GitHub Desktop.
Save ufobat/b165a66b1e3ab3228d1d0622fda20c9e to your computer and use it in GitHub Desktop.
use v6;
use Cro;
use Cro::TLS;
use Cro::TCP;
class Echo does Cro::Transform {
method consumes { Cro::TCP::Message }
method produces { Cro::TCP::Message }
method transformer(Supply $messages --> Supply) {
supply {
whenever $messages -> $m {
emit Cro::TCP::Message.new(
:data($m.data),
);
}
}
}
}
my Cro::Service $service = Cro.compose: Cro::TLS::Listener.new(:port(8000), :host("localhost")), Echo;
$service.start;
react {
whenever signal(SIGINT) { $service.stop; done }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment