mirror of
https://github.com/librespot-org/librespot.git
synced 2025-10-04 02:09:26 +02:00
Migrate core to tokio 1.0
This commit is contained in:
parent
efabb03631
commit
40e6355c34
16 changed files with 406 additions and 661 deletions
|
@ -1,7 +1,6 @@
|
|||
use byteorder::{BigEndian, ByteOrder, WriteBytesExt};
|
||||
use bytes::Bytes;
|
||||
use futures::sync::oneshot;
|
||||
use futures::{Async, Future, Poll};
|
||||
use futures::channel::oneshot;
|
||||
use std::collections::HashMap;
|
||||
use std::io::Write;
|
||||
|
||||
|
@ -47,7 +46,7 @@ impl AudioKeyManager {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn request(&self, track: SpotifyId, file: FileId) -> AudioKeyFuture<AudioKey> {
|
||||
pub async fn request(&self, track: SpotifyId, file: FileId) -> Result<AudioKey, AudioKeyError> {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
|
||||
let seq = self.lock(move |inner| {
|
||||
|
@ -57,7 +56,7 @@ impl AudioKeyManager {
|
|||
});
|
||||
|
||||
self.send_key_request(seq, track, file);
|
||||
AudioKeyFuture(rx)
|
||||
rx.await.map_err(|_| AudioKeyError)?
|
||||
}
|
||||
|
||||
fn send_key_request(&self, seq: u32, track: SpotifyId, file: FileId) {
|
||||
|
@ -70,18 +69,3 @@ impl AudioKeyManager {
|
|||
self.session().send_packet(0xc, data)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AudioKeyFuture<T>(oneshot::Receiver<Result<T, AudioKeyError>>);
|
||||
impl<T> Future for AudioKeyFuture<T> {
|
||||
type Item = T;
|
||||
type Error = AudioKeyError;
|
||||
|
||||
fn poll(&mut self) -> Poll<T, AudioKeyError> {
|
||||
match self.0.poll() {
|
||||
Ok(Async::Ready(Ok(value))) => Ok(Async::Ready(value)),
|
||||
Ok(Async::Ready(Err(err))) => Err(err),
|
||||
Ok(Async::NotReady) => Ok(Async::NotReady),
|
||||
Err(oneshot::Canceled) => Err(AudioKeyError),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue