Skip to content

Instantly share code, notes, and snippets.

@zoffixznet
Created July 28, 2016 18:52
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 zoffixznet/729acd14c65a3bc89f99df9619eba91f to your computer and use it in GitHub Desktop.
Save zoffixznet/729acd14c65a3bc89f99df9619eba91f to your computer and use it in GitHub Desktop.
my @servers = %( :host<irc.freenode.net>, :6667port, :promise(''), :sock(''), :!q ),
%( :host<localhost>, :4444port, :promise(''), :sock(''), :!q );
CONNECTION: for @servers -> $s {
$s<sock> = '';
say "Starting $s<host>";
$s<promise> = IO::Socket::Async.connect(|$s<host port>).then: {
say "$s<host>: $_.result()";
if .status ~~ Broken {
dd "ZOMFG! Can't connect!";
sleep ++$;
redo CONNECTION;
}
$s<sock> = .result;
react {
whenever $s<sock>.Supply {
say "Got stuff! $_";
}
}
$s<q> or redo CONNECTION;
say "Bah! $s<host>";
};
}
await Promise.allof: @servers».<promise>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment