Skip to content

Commit

Permalink
Wait for socket connection to come up before reading
Browse files Browse the repository at this point in the history
  • Loading branch information
junlarsen committed Apr 21, 2024
1 parent 92bfcf7 commit 6d04e45
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/slack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ pub async fn start_websocket_client() -> () {
// Spawn a worker thread to read messages from the channel and translate them into messages
// to be sent across the oneshot channel
loop {
if !socket.can_read() || !socket.can_write() {
tracing::warn!("Websocket is not ready to read or write, sleeping for 5 seconds");
tokio::time::sleep(std::time::Duration::from_secs(5)).await;
continue;
}
let msg = socket.read().expect("Failed to read from websocket");
// The Slack API promises that messages are sent as JSON, so we can safely assume that
// the message is a JSON string
Expand Down

0 comments on commit 6d04e45

Please sign in to comment.