fn create_connection(&self, checking_out: bool) -> Result<Connection> {
        self.inner
            .total_connection_count
            .fetch_add(1, Ordering::SeqCst);

        let mut connection = Connection::new(
            self.inner.next_connection_id.fetch_add(1, Ordering::SeqCst),
            self.inner.address.clone(),
            self.inner.generation.load(Ordering::SeqCst),
            self.inner.connect_timeout,
            self.inner.tls_options.clone(),
            self.inner.event_handler.clone(),
        )?;

        self.emit_event(|handler| {
            handler.handle_connection_created_event(connection.created_event())
        });

        let establish_result = self
            .inner
            .establisher
            .establish_connection(&mut connection, self.inner.credential.as_ref());

        if let Err(e) = establish_result {
            self.clear();

            if checking_out {
                self.emit_event(|handler| {
                    handler.handle_connection_checkout_failed_event(ConnectionCheckoutFailedEvent {
                        address: self.inner.address.clone(),
                        reason: ConnectionCheckoutFailedReason::ConnectionError,
                    })
                });
            }

            return Err(e);
        }

        self.emit_event(|handler| handler.handle_connection_ready_event(connection.ready_event()));

        Ok(connection)
    }
/// Helper method to create a connection and increment the total connection count.
Helper method to create a connection and increment the total connection count.
Helper method to create a connection and increment the total connection count .
fn create_connection(&self, checking_out: bool) -> Result<Connection> {
        self.inner
            .total_connection_count
            .fetch_add(1, Ordering::SeqCst);
        let mut connection = Connection::new(
            self.inner.next_connection_id.fetch_add(1, Ordering::SeqCst),
            self.inner.address.clone(),
            self.inner.generation.load(Ordering::SeqCst),
            self.inner.connect_timeout,
            self.inner.tls_options.clone(),
            self.inner.event_handler.clone(),
        )?;
        self.emit_event(|handler| {
            handler.handle_connection_created_event(connection.created_event())
        });
        let establish_result = self
            .inner
            .establisher
            .establish_connection(&mut connection, self.inner.credential.as_ref());
        if let Err(e) = establish_result {
            self.clear();
            if checking_out {
                self.emit_event(|handler| {
                    handler.handle_connection_checkout_failed_event(ConnectionCheckoutFailedEvent {
                        address: self.inner.address.clone(),
                        reason: ConnectionCheckoutFailedReason::ConnectionError,
                    })
                });
            }
            return Err(e);
        }
        self.emit_event(|handler| handler.handle_connection_ready_event(connection.ready_event()));
        Ok(connection)
    }
fn create_connection ( & self , checking_out : bool ) -> Result < Connection > { self . inner . total_connection_count . fetch_add ( 1 , Ordering :: SeqCst ) ; let mut connection = Connection :: new ( self . inner . next_connection_id . fetch_add ( 1 , Ordering :: SeqCst ) , self . inner . address . clone ( ) , self . inner . generation . load ( Ordering :: SeqCst ) , self . inner . connect_timeout , self . inner . tls_options . clone ( ) , self . inner . event_handler . clone ( ) , ) ? ; self . emit_event ( | handler | { handler . handle_connection_created_event ( connection . created_event ( ) ) } ) ; let establish_result = self . inner . establisher . establish_connection ( & mut connection , self . inner . credential . as_ref ( ) ) ; if let Err ( e ) = establish_result { self . clear ( ) ; if checking_out { self . emit_event ( | handler | { handler . handle_connection_checkout_failed_event ( ConnectionCheckoutFailedEvent { address : self . inner . address . clone ( ) , reason : ConnectionCheckoutFailedReason :: ConnectionError , } ) } ) ; } return Err ( e ) ; } self . emit_event ( | handler | handler . handle_connection_ready_event ( connection . ready_event ( ) ) ) ; Ok ( connection ) }
Helper method to create a connection and increment the total connection count.
Helper method to create a connection and increment the total connection count .
&self
checking_out
bool
&self
checking_out
bool