Created
July 28, 2016 18:52
-
-
Save zoffixznet/729acd14c65a3bc89f99df9619eba91f to your computer and use it in GitHub Desktop.
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
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