Skip to content

Commit

Permalink
Handle None from stream
Browse files Browse the repository at this point in the history
  • Loading branch information
jcdyer committed Aug 12, 2024
1 parent e5915d2 commit 8aafb81
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/listen/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ impl<'a> WebsocketBuilder<'a> {
let handle = self.handle().await?;

let (tx, rx) = mpsc::channel(1);
let mut is_done = false;
tokio::task::spawn(async move {
let mut handle = handle;
let mut tx = tx;
Expand Down Expand Up @@ -381,8 +382,8 @@ impl<'a> WebsocketBuilder<'a> {
}
}
// Receiving audio data from stream.
result = stream.next().fuse() => {
match result {
chunk = stream.next().fuse() => {
match chunk {
Some(Ok(audio)) => if let Err(err) = handle.send_data(audio.to_vec()).await {
// eprintln!("<stream> got audio");
if tx.send(Err(err)).await.is_err() {
Expand All @@ -396,6 +397,9 @@ impl<'a> WebsocketBuilder<'a> {
}
}
None => {
if is_done {
continue;
}
if let Err(err) = handle.finalize().await {
if tx.send(Err(err)).await.is_err() {
break;
Expand All @@ -407,6 +411,7 @@ impl<'a> WebsocketBuilder<'a> {
break;
}
}
is_done = true;
}
}
}
Expand Down

0 comments on commit 8aafb81

Please sign in to comment.