Skip to content

Commit

Permalink
remove async-trait
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed Dec 29, 2023
1 parent 1a9109a commit bd9be7e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
1 change: 0 additions & 1 deletion example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ path = "src/redis_registry.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
async-trait = "0.1"
tokio = { version = "1", features = ["full"] }
drpc = { version = "0.2", path = "../" }
serde = { version = "1", features = ["derive"] }
Expand Down
15 changes: 6 additions & 9 deletions example/src/redis_registry.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#[macro_use]
extern crate async_trait;
extern crate redis;

use drpc::codec::BinCodec;
Expand All @@ -15,7 +13,7 @@ use tokio::time::sleep;
/// docker run -it -d --name redis -p 6379:6379 redis
#[tokio::main]
async fn main() {
let manager = BalanceManger::<BinCodec>::new(ManagerConfig::default(), RedisCenter::new());
let manager = BalanceManger::new::<BinCodec>(ManagerConfig::default(), RedisCenter::new());
let m_clone = manager.clone();
tokio::spawn(async move {
spawn_server(m_clone).await;
Expand Down Expand Up @@ -45,7 +43,6 @@ impl RedisCenter {
}
}

#[async_trait]
impl RegistryCenter for RedisCenter {
async fn pull(&self) -> HashMap<String, Vec<String>> {
let mut m = HashMap::new();
Expand Down Expand Up @@ -83,20 +80,20 @@ impl RegistryCenter for RedisCenter {
addr.to_string(),
addr.to_string(),
)
.await
.map_err(|e| Error::from(e.to_string()))?;
.await
.map_err(|e| Error::from(e.to_string()))?;
l.expire::<String, ()>(
format!("{}{}", &self.server_prefix, service),
ex.as_secs() as usize,
)
.await
.map_err(|e| Error::from(e.to_string()))?;
.await
.map_err(|e| Error::from(e.to_string()))?;
}
return Ok(());
}
}

async fn spawn_server(manager: Arc<BalanceManger<BinCodec>>) {
async fn spawn_server(manager: Arc<BalanceManger<BinCodec, RedisCenter>>) {
tokio::spawn(async move {
manager
.spawn_push("test".to_string(), "127.0.0.1:10000".to_string())
Expand Down

0 comments on commit bd9be7e

Please sign in to comment.