mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-27 04:07:25 +01:00
import: Don't deadlock state receiver
This commit is contained in:
parent
2d5ce29aae
commit
8a00e4588c
3 changed files with 7 additions and 8 deletions
|
|
@ -2,7 +2,7 @@ use crate::{disc, folder};
|
|||
use crate::error::Result;
|
||||
use std::path::PathBuf;
|
||||
use std::thread;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::{oneshot, watch};
|
||||
|
||||
/// The current state of the import process.
|
||||
|
|
@ -36,7 +36,7 @@ pub struct ImportSession {
|
|||
pub(super) state_sender: watch::Sender<State>,
|
||||
|
||||
/// Receiver for state changes.
|
||||
pub(super) state_receiver: Mutex<watch::Receiver<State>>,
|
||||
pub(super) state_receiver: watch::Receiver<State>,
|
||||
}
|
||||
|
||||
impl ImportSession {
|
||||
|
|
@ -76,12 +76,13 @@ impl ImportSession {
|
|||
|
||||
/// Retrieve the current state of the import process.
|
||||
pub fn state(&self) -> State {
|
||||
self.state_receiver.lock().unwrap().borrow().clone()
|
||||
self.state_receiver.borrow().clone()
|
||||
}
|
||||
|
||||
/// Wait for the next state change and get the new state.
|
||||
pub async fn state_change(&self) -> State {
|
||||
match self.state_receiver.lock().unwrap().changed().await {
|
||||
let mut receiver = self.state_receiver.clone();
|
||||
match receiver.changed().await {
|
||||
Ok(()) => self.state(),
|
||||
Err(_) => State::Error,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue