From a1ea399a2e4c36949959fa22ecfac5fe583f1775 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Sun, 5 Jun 2016 10:34:38 -0400 Subject: Add lock --- lib/IRC/Client.pm6 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/IRC/Client.pm6 b/lib/IRC/Client.pm6 index b546866..cc18db2 100644 --- a/lib/IRC/Client.pm6 +++ b/lib/IRC/Client.pm6 @@ -18,11 +18,11 @@ has %.servers; method run { self!prep-servers; + my $lock = Lock.new; for %!servers.kv -> $s-name, $s-conf { - say "LAUNCHING $s-name [$s-conf]"; $s-conf - = IO::Socket::Async.connect( $s-conf, $s-conf ).then({ - $s-conf = .result; + = IO::Socket::Async.connect($s-conf, $s-conf).then: -> $v { + $lock.protect: { $s-conf = $v.result; }; self!ssay: "PASS $!password", :server($s-name) if $!password.defined; @@ -49,7 +49,7 @@ method run { } } $s-conf.close; - }); + }; } await Promise.allof: %!servers.values».; } @@ -92,7 +92,7 @@ method !plugs-that-can ($method) { } method !ssay (Str:D $msg, :$server = '*') { - $!debug and debug-print $msg, :out, :$server; + # $!debug and debug-print $msg, :out, :$server; %!servers{ $server }.print("$msg\n"); self; } @@ -112,7 +112,7 @@ sub debug-print (Str(Any) $str, :$in, :$out, :$sys, :$server) { require Terminal::ANSIColor; &colored = GLOBAL::Terminal::ANSIColor::EXPORT::DEFAULT::<&colored>; - } // sub (Str $s) { '' }; + } // sub (Str $s, $) { $s }; my $server-str = $server ?? colored($server, 'bold white on_green') ~ ' ' !! ''; -- cgit v1.1