Skip to content

Instantly share code, notes, and snippets.

@bioduds
Last active June 13, 2017 14:36
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 bioduds/fcb7d30703660b37618aa4df6cccda6a to your computer and use it in GitHub Desktop.
Save bioduds/fcb7d30703660b37618aa4df6cccda6a to your computer and use it in GitHub Desktop.
async hanging
### client sending message async
use v6;
use lib 'lib/network';
use client;
say "Running Test...";
loop {
sleep-until now+2;
my $client = EC::Network::Client.new( :destination( '35.167.61.56' ), :port( 5000 ) );
$client.send( :message( "Test to print" ) );
}
### the class
#unit package EC::Network:auth<github:bioduds>;
unit module EC::Network;
class Client {
has $.destination;
has $.port;
method send( :$message ) {
await IO::Socket::Async.connect( $!destination, $!port ).then( -> $p {
if $p.status {
given $p.result {
.print( $message ); ## this is sent
react {
whenever .Supply() -> $v {
say "Sending " ~ $v;
done;
}
}
.close;
}
}
});
}
}
#### the node on AWS
use v6;
use lib 'lib';
use socket;
say "Running Test...";
EC::Network::Socket.new.run;
### it's class
#unit package EC::Network:auth<github:bioduds>;
unit module EC::Network;
class Socket {
method run {
react {
whenever IO::Socket::Async.listen( '172.31.10.220', 5000 ) -> $conn {
whenever $conn.Supply( :bin ) -> $buf {
await $conn.write: $buf;
say $buf;
say $buf.decode( 'utf-8' );
}
}
}
}
}
## now it hanged and I need to reboot the server to make it work again, here's the output
#ubuntu@ip-172-31-10-220:~/client$ perl6 node.p6
#Running Test...
#Tried to get the result of a broken Promise
# in method run at /home/ubuntu/client/lib/socket.pm6 (socket) line 8
# in block <unit> at node.p6 line 7
#Original exception:
# address already in use
# in method run at /home/ubuntu/client/lib/socket.pm6 (socket) line 8
# in block <unit> at node.p6 line 7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment