use indexmap::IndexMap;
use mwapi::Client;
use tokio::time;
use tracing_subscriber::EnvFilter;
#[tokio::main]
async fn main() {
tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
.init();
let client = Client::new("https://en.wikipedia.org/w/api.php")
.await
.unwrap();
let mut handles = IndexMap::new();
for counter in 1..11 {
let client = client.clone();
let title = format!("Test_{counter}");
handles.insert(
title.to_string(),
tokio::spawn(async move {
if counter > 4 {
time::sleep(time::Duration::from_secs(2)).await;
}
client
.get_value([
("action", "query".to_string()),
("titles", title),
("prop", "info".to_string()),
])
.await
}),
);
}
for (orig_title, handle) in handles {
println!("awaiting on {}", &orig_title);
let resp = handle.await.unwrap().unwrap();
let recv_title = resp["query"]["pages"][0]["title"].as_str().unwrap();
println!("Expected {orig_title}, got {recv_title}");
dbg!(&resp);
}
drop(client);
time::sleep(time::Duration::from_secs(2)).await;
println!("all done");
}