/// Start async connecting to a remote server.
Start async connecting to a remote server.
Start async connecting to a remote server .
pub fn connect<RT: Runtime>(
        &self,
        connect_info: NP::ConnectInfo,
        runtime: &RT,
        network_settings: &NP::NetworkSettings,
    ) {
        debug!("Starting connection");
        let network_error_sender = self.error_channel.sender.clone();
        let connection_event_sender = self.new_connections.sender.clone();
        let settings = network_settings.clone();
        let connection_task_weak = Arc::downgrade(&self.connection_tasks);
        let task_count = self.connection_task_counts.fetch_add(1, Ordering::SeqCst);
        self.connection_tasks.insert(
            task_count,
            Box::new(runtime.spawn(async move {
                match NP::connect_task(connect_info, settings).await {
                    Ok(connection) => connection_event_sender
                        .send(connection)
                        .await
                        .expect("Connection channel has closed"),
                    Err(e) => network_error_sender
                        .send(e)
                        .await
                        .expect("Error channel has closed."),
                };
                // Remove the connection task from our dictionary of connection tasks
                connection_task_weak
                    .upgrade()
                    .expect("Network dropped")
                    .remove(&task_count);
            })),
        );
    }
pub fn connect < RT : Runtime > ( & self , connect_info : NP :: ConnectInfo , runtime : & RT , network_settings : & NP :: NetworkSettings , ) { debug ! ( " " ) ; let network_error_sender = self . error_channel . sender . clone ( ) ; let connection_event_sender = self . new_connections . sender . clone ( ) ; let settings = network_settings . clone ( ) ; let connection_task_weak = Arc :: downgrade ( & self . connection_tasks ) ; let task_count = self . connection_task_counts . fetch_add ( 1 , Ordering :: SeqCst ) ; self . connection_tasks . insert ( task_count , Box :: new ( runtime . spawn ( async move { match NP :: connect_task ( connect_info , settings ) . await { Ok ( connection ) => connection_event_sender . send ( connection ) . await . expect ( " " ) , Err ( e ) => network_error_sender . send ( e ) . await . expect ( " " ) , } ; // Remove the connection task from our dictionary of connection tasks connection_task_weak . upgrade ( ) . expect ( " " ) . remove ( & task_count ) ; } ) ) , ) ; }
Start async connecting to a remote server.
Start async connecting to a remote server .
&self
connect_info
NP::ConnectInfo
runtime
&RT
network_settings
&NP::NetworkSettings