my $timeout = 5;
for 21,22,80,3306 ->$port {
print "-->$port\r";
#say "\r";
await Promise.anyof(
    Promise.in($timeout),
    start {
      #sleep 6;
        my $c = IO::Socket::INET.new(:host<localhost>, :port($port));
        say "-->$port [Open]" if so $c;
        my $p = $c.recv();
        say $p;
    },
);
}

 

anyod里面的线程如果有一个返回 kept时, 就马上返回, 设置超时时间为 $timeout 后, 当第一个 Promise.in($timeout) 时间到达时会返回, 里面的 Socket就不能继续运行了。

 

相关文章:

  • 2021-10-22
  • 2021-11-13
  • 2021-10-18
  • 2018-01-22
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-05
相关资源
相似解决方案