#![allow(
clippy::print_stdout,
clippy::uninlined_format_args,
reason = "example code that demonstrates library usage"
)]
use std::time::Duration;
use waitup::{Target, WaitConfig, wait_for_connection};
#[tokio::main]
async fn main() -> Result<(), waitup::WaitForError> {
println!("🔍 Waiting for TCP service to become available...");
let target = Target::tcp("localhost", 8080)?;
let config = WaitConfig::builder()
.timeout(Duration::from_secs(30))
.interval(Duration::from_secs(1))
.max_interval(Duration::from_secs(5))
.build();
let result = wait_for_connection(&[target], &config).await?;
println!("✅ Service is ready!");
println!(
"📊 Connection successful in {:?} with {} attempts",
result.elapsed, result.attempts
);
for target_result in &result.target_results {
println!(
" - {}: {} in {:?} ({} attempts)",
target_result.target.display(),
if target_result.success {
"✅ Success"
} else {
"❌ Failed"
},
target_result.elapsed,
target_result.attempts
);
}
Ok(())
}