23 lines
538 B
Rust
Raw Normal View History

2022-09-14 17:36:16 +02:00
use std::time::Duration;
use tokio::net::TcpStream;
use tokio::time;
/// Check whether a given port is open or not
pub async fn is_port_open(port: u16) -> bool {
2022-10-01 20:44:01 +02:00
TcpStream::connect(("127.0.0.1", port)).await.is_ok()
2022-09-14 17:36:16 +02:00
}
/// Wait for a port to become available
pub async fn wait_for_port(port: u16) {
for _ in 0..50 {
if is_port_open(port).await {
return;
}
time::sleep(Duration::from_millis(10)).await;
}
eprintln!("Port {} did not open in time!", port);
std::process::exit(2);
}