mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Replace pin_project and updated dependencies
This commit is contained in:
parent
0895f17f8a
commit
6c9d8c8d83
6 changed files with 56 additions and 55 deletions
|
@ -16,11 +16,11 @@ bit-set = "0.5"
|
|||
byteorder = "1.4"
|
||||
bytes = "1.0"
|
||||
futures = "0.3"
|
||||
lewton = "0.9"
|
||||
lewton = "0.10"
|
||||
log = "0.4"
|
||||
num-bigint = "0.3"
|
||||
num-traits = "0.2"
|
||||
pin-project = "1.0"
|
||||
pin-project-lite = "0.2.4"
|
||||
tempfile = "3.1"
|
||||
|
||||
librespot-tremor = { version = "0.1.0", optional = true }
|
||||
|
|
|
@ -689,20 +689,21 @@ async fn audio_file_fetch(
|
|||
future::select_all(vec![f1, f2, f3]).await
|
||||
}*/
|
||||
|
||||
#[pin_project]
|
||||
struct AudioFileFetch {
|
||||
session: Session,
|
||||
shared: Arc<AudioFileShared>,
|
||||
output: Option<NamedTempFile>,
|
||||
pin_project! {
|
||||
struct AudioFileFetch {
|
||||
session: Session,
|
||||
shared: Arc<AudioFileShared>,
|
||||
output: Option<NamedTempFile>,
|
||||
|
||||
file_data_tx: mpsc::UnboundedSender<ReceivedData>,
|
||||
#[pin]
|
||||
file_data_rx: mpsc::UnboundedReceiver<ReceivedData>,
|
||||
file_data_tx: mpsc::UnboundedSender<ReceivedData>,
|
||||
#[pin]
|
||||
file_data_rx: mpsc::UnboundedReceiver<ReceivedData>,
|
||||
|
||||
#[pin]
|
||||
stream_loader_command_rx: mpsc::UnboundedReceiver<StreamLoaderCommand>,
|
||||
complete_tx: Option<oneshot::Sender<NamedTempFile>>,
|
||||
network_response_times_ms: Vec<usize>,
|
||||
#[pin]
|
||||
stream_loader_command_rx: mpsc::UnboundedReceiver<StreamLoaderCommand>,
|
||||
complete_tx: Option<oneshot::Sender<NamedTempFile>>,
|
||||
network_response_times_ms: Vec<usize>,
|
||||
}
|
||||
}
|
||||
|
||||
impl AudioFileFetch {
|
||||
|
@ -853,8 +854,6 @@ impl AudioFileFetch {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
fn poll_file_data_rx(&mut self, cx: &mut Context<'_>) -> Poll<()> {
|
||||
loop {
|
||||
match Pin::new(&mut self.file_data_rx).poll_next(cx) {
|
||||
|
@ -923,12 +922,10 @@ impl AudioFileFetch {
|
|||
|
||||
if full {
|
||||
self.finish();
|
||||
return Poll::Ready(())
|
||||
return Poll::Ready(());
|
||||
}
|
||||
}
|
||||
Poll::Pending => {
|
||||
return Poll::Pending
|
||||
}
|
||||
Poll::Pending => return Poll::Pending,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -936,27 +933,22 @@ impl AudioFileFetch {
|
|||
fn poll_stream_loader_command_rx(&mut self, cx: &mut Context<'_>) -> Poll<()> {
|
||||
loop {
|
||||
match Pin::new(&mut self.stream_loader_command_rx).poll_next(cx) {
|
||||
Poll::Ready(None) =>
|
||||
return Poll::Ready(()),
|
||||
Poll::Ready(Some(cmd)) => {
|
||||
match cmd {
|
||||
StreamLoaderCommand::Fetch(request) => {
|
||||
self.download_range(request.start, request.length);
|
||||
}
|
||||
StreamLoaderCommand::RandomAccessMode() => {
|
||||
*(self.shared.download_strategy.lock().unwrap()) =
|
||||
DownloadStrategy::RandomAccess();
|
||||
}
|
||||
StreamLoaderCommand::StreamMode() => {
|
||||
|
||||
*(self.shared.download_strategy.lock().unwrap()) =
|
||||
DownloadStrategy::Streaming();
|
||||
}
|
||||
StreamLoaderCommand::Close() => return Poll::Ready(())
|
||||
|
||||
Poll::Ready(None) => return Poll::Ready(()),
|
||||
Poll::Ready(Some(cmd)) => match cmd {
|
||||
StreamLoaderCommand::Fetch(request) => {
|
||||
self.download_range(request.start, request.length);
|
||||
}
|
||||
}
|
||||
Poll::Pending => return Poll::Pending
|
||||
StreamLoaderCommand::RandomAccessMode() => {
|
||||
*(self.shared.download_strategy.lock().unwrap()) =
|
||||
DownloadStrategy::RandomAccess();
|
||||
}
|
||||
StreamLoaderCommand::StreamMode() => {
|
||||
*(self.shared.download_strategy.lock().unwrap()) =
|
||||
DownloadStrategy::Streaming();
|
||||
}
|
||||
StreamLoaderCommand::Close() => return Poll::Ready(()),
|
||||
},
|
||||
Poll::Pending => return Poll::Pending,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -974,11 +966,11 @@ impl Future for AudioFileFetch {
|
|||
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
|
||||
if let Poll::Ready(()) = self.poll_stream_loader_command_rx(cx) {
|
||||
return Poll::Ready(())
|
||||
return Poll::Ready(());
|
||||
}
|
||||
|
||||
if let Poll::Ready(()) = self.poll_file_data_rx(cx) {
|
||||
return Poll::Ready(())
|
||||
return Poll::Ready(());
|
||||
}
|
||||
|
||||
if let DownloadStrategy::Streaming() = self.get_download_strategy() {
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#![allow(clippy::unused_io_amount)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
#[macro_use]
|
||||
extern crate pin_project;
|
||||
extern crate pin_project_lite;
|
||||
|
||||
extern crate aes_ctr;
|
||||
extern crate bit_set;
|
||||
|
|
|
@ -20,14 +20,14 @@ bytes = "1.0"
|
|||
futures = { version = "0.3", features = ["bilock", "unstable"] }
|
||||
hmac = "0.7"
|
||||
httparse = "1.3"
|
||||
hyper = { version = "0.14", features = ["client", "tcp", "http1", "http2", "stream"] }
|
||||
hyper = { version = "0.14", features = ["client", "tcp", "http1", "http2"] }
|
||||
log = "0.4"
|
||||
num-bigint = "0.3"
|
||||
num-integer = "0.1"
|
||||
num-traits = "0.2"
|
||||
once_cell = "1.5.2"
|
||||
pbkdf2 = "0.3"
|
||||
pin-project = "1.0"
|
||||
pin-project-lite = "0.2.4"
|
||||
protobuf = "~2.14.0"
|
||||
rand = "0.7"
|
||||
serde = "1.0"
|
||||
|
@ -35,7 +35,7 @@ serde_derive = "1.0"
|
|||
serde_json = "1.0"
|
||||
sha-1 = "~0.8"
|
||||
shannon = "0.2.0"
|
||||
tokio = { version = "1.0", features = ["io-util", "rt-multi-thread", "macros" ] }
|
||||
tokio = { version = "1.0", features = ["io-util", "rt-multi-thread"] }
|
||||
tokio-util = { version = "0.6", features = ["codec"] }
|
||||
url = "1.7"
|
||||
uuid = { version = "0.8", features = ["v4"] }
|
||||
|
@ -43,3 +43,6 @@ uuid = { version = "0.8", features = ["v4"] }
|
|||
[build-dependencies]
|
||||
rand = "0.7"
|
||||
vergen = "3.0.4"
|
||||
|
||||
[dev-dependencies]
|
||||
tokio = {version = "1.0", features = ["macros"] }
|
|
@ -5,7 +5,7 @@ extern crate log;
|
|||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
#[macro_use]
|
||||
extern crate pin_project;
|
||||
extern crate pin_project_lite;
|
||||
extern crate aes;
|
||||
extern crate base64;
|
||||
extern crate byteorder;
|
||||
|
@ -25,7 +25,7 @@ extern crate serde;
|
|||
extern crate serde_json;
|
||||
extern crate sha1;
|
||||
extern crate shannon;
|
||||
extern crate tokio;
|
||||
pub extern crate tokio;
|
||||
extern crate tokio_util;
|
||||
extern crate url;
|
||||
extern crate uuid;
|
||||
|
|
|
@ -31,14 +31,18 @@ pub struct MercuryPending {
|
|||
callback: Option<oneshot::Sender<Result<MercuryResponse, MercuryError>>>,
|
||||
}
|
||||
|
||||
#[pin_project]
|
||||
pub struct MercuryFuture<T>(#[pin] oneshot::Receiver<Result<T, MercuryError>>);
|
||||
pin_project! {
|
||||
pub struct MercuryFuture<T> {
|
||||
#[pin]
|
||||
receiver: oneshot::Receiver<Result<T, MercuryError>>
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Future for MercuryFuture<T> {
|
||||
type Output = Result<T, MercuryError>;
|
||||
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
match self.project().0.poll(cx) {
|
||||
match self.project().receiver.poll(cx) {
|
||||
Poll::Ready(Ok(x)) => Poll::Ready(x),
|
||||
Poll::Ready(Err(_)) => Poll::Ready(Err(MercuryError)),
|
||||
Poll::Pending => Poll::Pending,
|
||||
|
@ -73,7 +77,7 @@ impl MercuryManager {
|
|||
let data = req.encode(&seq);
|
||||
|
||||
self.session().send_packet(cmd, data);
|
||||
MercuryFuture(rx)
|
||||
MercuryFuture { receiver: rx }
|
||||
}
|
||||
|
||||
pub fn get<T: Into<String>>(&self, uri: T) -> MercuryFuture<MercuryResponse> {
|
||||
|
|
Loading…
Reference in a new issue