my @s = %( :host, :6667port, :promise(''), :sock(''), :!q, :0e ), %( :host, :4444port, :promise(''), :sock(''), :!q, :0e ); my Channel $c .= new; sub connect-it ($s) { say "Connecting $s:$s"; $s = ''; $s = IO::Socket::Async.connect(|$s).then: sub ($_) { if .status ~~ Broken { dd "ZOMFG! Can't connect!"; $s = True if $s++ > 4; sleep 1; $c.send: ['broken', $s]; return; } $s = .result; react { say "Loooop"; whenever $s.Supply { say "Got stuff! $_"; } } $s = True if $s++ > 3; $c.send: ['closed', $s]; CATCH { default { warn $_; warn .backtrace; } } } } connect-it $_ for @s; loop { say "Starting listen"; my $v = $c.receive; dd $v; connect-it $v[1] unless $v[1]; unless @s.grep({!.}) { say 'Bailing out'; last; } }