pub async fn new(options: PuppetOptions) -> Result<Puppet<Self>, PuppetError> {
        let endpoint = if let Some(endpoint) = options.endpoint {
            endpoint
        } else if let Some(token) = options.token {
            match discover(token).await {
                Ok(endpoint) => endpoint,
                Err(e) => return Err(e),
            }
        } else {
            return Err(PuppetError::InvalidToken);
        };

        match PuppetClient::connect(endpoint.clone()).await {
            Ok(mut client) => {
                info!("Connected to endpoint {}", endpoint);
                let response = client.event(EventRequest {}).await;
                match response {
                    Ok(response) => {
                        info!("Subscribed to event stream");
                        let addr = PuppetServiceInner::new().start();
                        let puppet_service = Self {
                            client_: client,
                            addr: addr.clone(),
                        };
                        let puppet = Puppet::new(puppet_service);
                        let callback_addr = puppet.self_addr();
                        addr.do_send(PuppetServiceInternalMessage::SetupCallback(callback_addr));
                        addr.do_send(PuppetServiceInternalMessage::SetupStream(response.into_inner()));
                        Ok(puppet)
                    }
                    Err(e) => Err(PuppetError::Network(format!(
                        "Failed to establish event stream, reason: {}",
                        e
                    ))),
                }
            }
            Err(e) => Err(PuppetError::Network(format!(
                "Failed to establish RPC connection, reason: {}",
                e
            ))),
        }
    }
/// Create puppet instance from puppet options.
///
/// First use endpoint, if endpoint is not given, try token instead.
Create puppet instance from puppet options.
First use endpoint, if endpoint is not given, try token instead.
Create puppet instance from puppet options . First use endpoint if endpoint is not given try token instead .
pub async fn new(options: PuppetOptions) -> Result<Puppet<Self>, PuppetError> {
        let endpoint = if let Some(endpoint) = options.endpoint {
            endpoint
        } else if let Some(token) = options.token {
            match discover(token).await {
                Ok(endpoint) => endpoint,
                Err(e) => return Err(e),
            }
        } else {
            return Err(PuppetError::InvalidToken);
        };
        match PuppetClient::connect(endpoint.clone()).await {
            Ok(mut client) => {
                info!("Connected to endpoint {}", endpoint);
                let response = client.event(EventRequest {}).await;
                match response {
                    Ok(response) => {
                        info!("Subscribed to event stream");
                        let addr = PuppetServiceInner::new().start();
                        let puppet_service = Self {
                            client_: client,
                            addr: addr.clone(),
                        };
                        let puppet = Puppet::new(puppet_service);
                        let callback_addr = puppet.self_addr();
                        addr.do_send(PuppetServiceInternalMessage::SetupCallback(callback_addr));
                        addr.do_send(PuppetServiceInternalMessage::SetupStream(response.into_inner()));
                        Ok(puppet)
                    }
                    Err(e) => Err(PuppetError::Network(format!(
                        "Failed to establish event stream, reason: {}",
                        e
                    ))),
                }
            }
            Err(e) => Err(PuppetError::Network(format!(
                "Failed to establish RPC connection, reason: {}",
                e
            ))),
        }
    }
pub async fn new ( options : PuppetOptions ) -> Result < Puppet < Self > , PuppetError > { let endpoint = if let Some ( endpoint ) = options . endpoint { endpoint } else if let Some ( token ) = options . token { match discover ( token ) . await { Ok ( endpoint ) => endpoint , Err ( e ) => return Err ( e ) , } } else { return Err ( PuppetError :: InvalidToken ) ; } ; match PuppetClient :: connect ( endpoint . clone ( ) ) . await { Ok ( mut client ) => { info ! ( " " endpoint ) ; let response = client . event ( EventRequest { } ) . await ; match response { Ok ( response ) => { info ! ( " " ) ; let addr = PuppetServiceInner :: new ( ) . start ( ) ; let puppet_service = Self { client_ : client , addr : addr . clone ( ) , } ; let puppet = Puppet :: new ( puppet_service ) ; let callback_addr = puppet . self_addr ( ) ; addr . do_send ( PuppetServiceInternalMessage :: SetupCallback ( callback_addr ) ) ; addr . do_send ( PuppetServiceInternalMessage :: SetupStream ( response . into_inner ( ) ) ) ; Ok ( puppet ) } Err ( e ) => Err ( PuppetError :: Network ( format ! ( " " e ) ) ) , } } Err ( e ) => Err ( PuppetError :: Network ( format ! ( " " e ) ) ) , } }
Create puppet instance from puppet options.
Create puppet instance from puppet options .
options
PuppetOptions
options
PuppetOptions