mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Better handling of shutdown
This commit is contained in:
parent
d2161ff75f
commit
9873eaf2a0
5 changed files with 14 additions and 3 deletions
1
src/cache/mod.rs
vendored
1
src/cache/mod.rs
vendored
|
@ -5,6 +5,7 @@ use std::fs::File;
|
|||
use util::{FileId, mkdir_existing};
|
||||
use authentication::Credentials;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Cache {
|
||||
root: PathBuf,
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ fn list_backends() {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Setup {
|
||||
backend: &'static (Fn(Option<String>) -> Box<Sink> + Send + Sync),
|
||||
cache: Option<Cache>,
|
||||
|
|
|
@ -3,6 +3,7 @@ use futures::{future, Future};
|
|||
use std::borrow::Cow;
|
||||
use std::io::{Read, Seek};
|
||||
use std::mem;
|
||||
use std::sync::mpsc::{RecvError, TryRecvError};
|
||||
use std::thread;
|
||||
use std;
|
||||
use vorbis::{self, VorbisError};
|
||||
|
@ -174,9 +175,16 @@ impl PlayerInternal {
|
|||
fn run(mut self) {
|
||||
loop {
|
||||
let cmd = if self.state.is_playing() {
|
||||
self.commands.try_recv().ok()
|
||||
match self.commands.try_recv() {
|
||||
Ok(cmd) => Some(cmd),
|
||||
Err(TryRecvError::Empty) => None,
|
||||
Err(TryRecvError::Disconnected) => return,
|
||||
}
|
||||
} else {
|
||||
Some(self.commands.recv().unwrap())
|
||||
match self.commands.recv() {
|
||||
Ok(cmd) => Some(cmd),
|
||||
Err(RecvError) => return,
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(cmd) = cmd {
|
||||
|
|
|
@ -40,6 +40,7 @@ impl FromStr for Bitrate {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Config {
|
||||
pub user_agent: String,
|
||||
pub name: String,
|
||||
|
|
|
@ -160,7 +160,7 @@ impl Spirc {
|
|||
}
|
||||
|
||||
pub fn shutdown(&self) {
|
||||
mpsc::UnboundedSender::send(&self.commands, SpircCommand::Shutdown).unwrap();
|
||||
let _ = mpsc::UnboundedSender::send(&self.commands, SpircCommand::Shutdown);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue