Better handling of shutdown

This commit is contained in:
Paul Lietar 2017-01-31 08:21:30 +00:00
parent d2161ff75f
commit 9873eaf2a0
5 changed files with 14 additions and 3 deletions

1
src/cache/mod.rs vendored
View file

@ -5,6 +5,7 @@ use std::fs::File;
use util::{FileId, mkdir_existing};
use authentication::Credentials;
#[derive(Clone)]
pub struct Cache {
root: PathBuf,
}

View file

@ -62,6 +62,7 @@ fn list_backends() {
}
}
#[derive(Clone)]
struct Setup {
backend: &'static (Fn(Option<String>) -> Box<Sink> + Send + Sync),
cache: Option<Cache>,

View file

@ -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 {

View file

@ -40,6 +40,7 @@ impl FromStr for Bitrate {
}
}
#[derive(Clone)]
pub struct Config {
pub user_agent: String,
pub name: String,

View file

@ -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);
}
}