Skip to content

Commit

Permalink
chore: Update examples (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
sugyan authored Mar 5, 2024
1 parent 83feb31 commit 1a5474c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
10 changes: 5 additions & 5 deletions examples/concurrent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
atrium-api = "0.14"
atrium-xrpc-client = "0.2"
clap = { version = "4.4.7", features = ["derive"] }
futures = "0.3.29"
tokio = { version = "1.33.0", features = ["macros", "rt-multi-thread"] }
atrium-api = "0.18.1"
atrium-xrpc-client = "0.4.0"
clap = { version = "4.5.1", features = ["derive"] }
futures = "0.3.30"
tokio = { version = "1.36.0", features = ["macros", "rt-multi-thread"] }
4 changes: 3 additions & 1 deletion examples/concurrent/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let handles = actors
.iter()
.map(|&actor| {
println!("fetching profile of {actor}...");
let agent = Arc::clone(&agent);
tokio::spawn(async move {
agent
Expand All @@ -36,13 +37,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.bsky
.actor
.get_profile(atrium_api::app::bsky::actor::get_profile::Parameters {
actor: actor.into(),
actor: actor.parse().expect("invalid actor"),
})
.await
})
})
.collect::<Vec<_>>();
let results = join_all(handles).await;
println!("{} profiles fetched!", results.len());
for (actor, result) in actors.iter().zip(results) {
println!("{actor}: {:#?}", result?);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/firehose/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2021"
anyhow = "1.0.80"
atrium-api = { version = "0.18.1", features = ["dag-cbor"] }
chrono = "0.4.34"
futures = "0.3.28"
futures = "0.3.30"
ipld-core = { version = "0.2.0", features = ["serde"] }
rs-car = "0.4.1"
serde_ipld_dagcbor = { git = "https://github.com/ipld/serde_ipld_dagcbor.git", rev = "297a6c26c8c89807e6602cab9803ef2c4ae8b459" }
Expand Down
11 changes: 7 additions & 4 deletions examples/firehose/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use anyhow::{anyhow, Result};
use atrium_api::app::bsky::feed::post::Record;
use atrium_api::com::atproto::sync::subscribe_repos::{Commit, NSID};
use atrium_api::types::{CidLink, Collection};
Expand All @@ -23,7 +24,9 @@ impl RepoSubscription {
if let Ok(Frame::Message(Some(t), message)) = result {
if t.as_str() == "#commit" {
let commit = serde_ipld_dagcbor::from_reader(message.body.as_slice())?;
handler.handle_commit(&commit).await?;
if let Err(err) = handler.handle_commit(&commit).await {
eprintln!("FAILED: {err:?}");
}
}
}
}
Expand All @@ -44,7 +47,7 @@ impl Subscription for RepoSubscription {
struct Firehose;

impl CommitHandler for Firehose {
async fn handle_commit(&self, commit: &Commit) -> Result<(), Box<dyn std::error::Error>> {
async fn handle_commit(&self, commit: &Commit) -> Result<()> {
for op in &commit.ops {
let collection = op.path.split('/').next().expect("op.path is empty");
if op.action != "create" || collection != atrium_api::app::bsky::feed::Post::NSID {
Expand All @@ -62,11 +65,11 @@ impl CommitHandler for Firehose {
println!(" {line}");
}
} else {
panic!(
return Err(anyhow!(
"FAILED: could not find item with operation cid {:?} out of {} items",
op.cid,
items.len()
);
));
}
}
Ok(())
Expand Down
6 changes: 2 additions & 4 deletions examples/firehose/src/subscription.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::stream::frames::Frame;
use anyhow::Result;
use atrium_api::com::atproto::sync::subscribe_repos::Commit;
use std::future::Future;

Expand All @@ -8,8 +9,5 @@ pub trait Subscription {
}

pub trait CommitHandler {
fn handle_commit(
&self,
commit: &Commit,
) -> impl Future<Output = Result<(), Box<dyn std::error::Error>>>;
fn handle_commit(&self, commit: &Commit) -> impl Future<Output = Result<()>>;
}

0 comments on commit 1a5474c

Please sign in to comment.