diff options
| author | hozan23 <hozan23@proton.me> | 2023-11-15 17:16:39 +0300 | 
|---|---|---|
| committer | hozan23 <hozan23@proton.me> | 2023-11-15 17:16:39 +0300 | 
| commit | 78884caca030104557ca277dd3a41cefb70f5be8 (patch) | |
| tree | c33650dfe44a219e395dff1966d298b58b09acb3 /p2p/src/discovery/lookup.rs | |
| parent | f0729022589ee8e48b5558ab30462f95d06fe6df (diff) | |
improve the TaskGroup API
the TaskGroup now holds an Executor instead of passing it when calling
its spawn method
also, define a global executor `Executor<'static>` and use static
lifetime instead of a lifetime placeholder
This improvement simplify the code for spawning a new task. There is no
need to pass the executor around.
Diffstat (limited to 'p2p/src/discovery/lookup.rs')
| -rw-r--r-- | p2p/src/discovery/lookup.rs | 15 | 
1 files changed, 9 insertions, 6 deletions
| diff --git a/p2p/src/discovery/lookup.rs b/p2p/src/discovery/lookup.rs index 94da900..52aa339 100644 --- a/p2p/src/discovery/lookup.rs +++ b/p2p/src/discovery/lookup.rs @@ -5,7 +5,7 @@ use log::{error, trace};  use rand::{rngs::OsRng, seq::SliceRandom, RngCore};  use smol::lock::{Mutex, RwLock}; -use karyons_core::{async_utils::timeout, utils::decode, Executor}; +use karyons_core::{async_utils::timeout, utils::decode, GlobalExecutor};  use karyons_net::{Conn, Endpoint}; @@ -59,15 +59,18 @@ impl LookupService {          table: Arc<Mutex<RoutingTable>>,          config: Arc<Config>,          monitor: Arc<Monitor>, +        ex: GlobalExecutor,      ) -> Self {          let inbound_slots = Arc::new(ConnectionSlots::new(config.lookup_inbound_slots));          let outbound_slots = Arc::new(ConnectionSlots::new(config.lookup_outbound_slots)); -        let listener = Listener::new(inbound_slots.clone(), monitor.clone()); +        let listener = Listener::new(inbound_slots.clone(), monitor.clone(), ex.clone()); +          let connector = Connector::new(              config.lookup_connect_retries,              outbound_slots.clone(),              monitor.clone(), +            ex,          );          let listen_endpoint = config @@ -88,8 +91,8 @@ impl LookupService {      }      /// Start the lookup service. -    pub async fn start(self: &Arc<Self>, ex: Executor<'_>) -> Result<()> { -        self.start_listener(ex).await?; +    pub async fn start(self: &Arc<Self>) -> Result<()> { +        self.start_listener().await?;          Ok(())      } @@ -233,7 +236,7 @@ impl LookupService {      }      /// Start a listener. -    async fn start_listener(self: &Arc<Self>, ex: Executor<'_>) -> Result<()> { +    async fn start_listener(self: &Arc<Self>) -> Result<()> {          let addr = match &self.listen_endpoint {              Some(a) => a.read().await.addr()?.clone(),              None => return Ok(()), @@ -248,7 +251,7 @@ impl LookupService {              Ok(())          }; -        self.listener.start(ex, endpoint.clone(), callback).await?; +        self.listener.start(endpoint.clone(), callback).await?;          Ok(())      } | 
