Skip to content

Commit

Permalink
chore: add leaderboard example
Browse files Browse the repository at this point in the history
  • Loading branch information
RealHinome authored Mar 9, 2024
1 parent bab913a commit 3b9c54f
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions squid/examples/client.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
use serde::Deserialize;
use squid::squid_client::SquidClient;
use squid::LeaderboardRequest;

#[derive(Debug, Deserialize)]
pub struct Leaderboard {
pub words: Vec<Word>,
pub mod squid {
tonic::include_proto!("squid");
}

#[derive(Debug, Deserialize)]
pub struct Word {
pub word: String,
pub occurrence: usize,
}

fn main() {
#[tokio::main]
async fn main() {
// Calculate time taken.
let now: u128 = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.expect("Time went backwards")
.as_millis();

// Get leaderboard of 10 most used words.
let response = SquidClient::connect("http://localhost:50051")
.await
.unwrap()
.leaderboard(LeaderboardRequest { length: 10 })
.await
.unwrap()
.into_inner();

println!(
"Received in {}ms",
"Received {:?} in {}ms",
response.word,
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.expect("Time went backwards")
Expand Down

0 comments on commit 3b9c54f

Please sign in to comment.