pub async fn read_once(&mut self) -> Result<()> {
        tokio::select! {
            frame = self.websocket.next() => {
                match frame {
                    Some(Ok(message)) if message.is_text() || message.is_binary() => {
                        match self.options.format {
                            TailFormat::Json => {
                                println!("{}", message);
                                Ok(())
                            },
                            TailFormat::Pretty => match serde_json::from_str::<TraceEvent>(&message.to_string()) {
                                Ok(event) => {
                                    println!("{}", event);
                                    Ok(())
                                },
                                Err(err) => {
                                    log::debug!("Failed to pretty-print tail: {}", err);
                                    self.close(CloseCode::Protocol, "wrangler is closing due to a protocol violation").await
                                },
                            }
                        }
                    },
                    Some(Ok(message)) if message.is_close() => {
                        anyhow::bail!("Received close from WebSocket tail: {}", message)
                    },
                    Some(Err(err)) => {
                        log::debug!("Received error from WebSocket tail: {}", err);
                        self.close(CloseCode::Abnormal, "wrangler is closing due to an error").await
                    },
                    _ => Ok(()),
                }
            },
            _ = tokio::signal::ctrl_c() => {
                self.close(CloseCode::Away, "wrangler is closing due to ctrl-c").await
            },
            _ = tokio::time::sleep_until(self.tail.expires_at) => {
                self.close(CloseCode::Normal, "wrangler is closing due to expiration").await
            }
        }
    }
/// Reads a message from the WebSocket and prints it.
Reads a message from the WebSocket and prints it.
Reads a message from the WebSocket and prints it .
pub async fn read_once(&mut self) -> Result<()> {
        tokio::select! {
            frame = self.websocket.next() => {
                match frame {
                    Some(Ok(message)) if message.is_text() || message.is_binary() => {
                        match self.options.format {
                            TailFormat::Json => {
                                println!("{}", message);
                                Ok(())
                            },
                            TailFormat::Pretty => match serde_json::from_str::<TraceEvent>(&message.to_string()) {
                                Ok(event) => {
                                    println!("{}", event);
                                    Ok(())
                                },
                                Err(err) => {
                                    log::debug!("Failed to pretty-print tail: {}", err);
                                    self.close(CloseCode::Protocol, "wrangler is closing due to a protocol violation").await
                                },
                            }
                        }
                    },
                    Some(Ok(message)) if message.is_close() => {
                        anyhow::bail!("Received close from WebSocket tail: {}", message)
                    },
                    Some(Err(err)) => {
                        log::debug!("Received error from WebSocket tail: {}", err);
                        self.close(CloseCode::Abnormal, "wrangler is closing due to an error").await
                    },
                    _ => Ok(()),
                }
            },
            _ = tokio::signal::ctrl_c() => {
                self.close(CloseCode::Away, "wrangler is closing due to ctrl-c").await
            },
            _ = tokio::time::sleep_until(self.tail.expires_at) => {
                self.close(CloseCode::Normal, "wrangler is closing due to expiration").await
            }
        }
    }
pub async fn read_once ( & mut self ) -> Result < ( ) > { tokio :: select ! { frame self websocket next ( ) { match frame { Some ( Ok ( message ) ) if message is_text ( ) message is_binary ( ) { match self options format { TailFormat Json { println ( " " message ) Ok ( ( ) ) } TailFormat Pretty match serde_json from_str TraceEvent ( message to_string ( ) ) { Ok ( event ) { println ( " " event ) Ok ( ( ) ) } Err ( err ) { log debug ( " " err ) self close ( CloseCode Protocol " " ) await } } } } Some ( Ok ( message ) ) if message is_close ( ) { anyhow bail ( " " message ) } Some ( Err ( err ) ) { log debug ( " " err ) self close ( CloseCode Abnormal " " ) await } Ok ( ( ) ) } } tokio signal ctrl_c ( ) { self close ( CloseCode Away " " ) await } tokio time sleep_until ( self tail expires_at ) { self close ( CloseCode Normal " " ) await } } }
Reads a message from the WebSocket and prints it.
Reads a message from the WebSocket and prints it .
&mut self
&mut self