Songbird: Tokio 1.0 (#36)

Migrates to the new version of tokio, requiring channel and sleep changes in a few locations. Additionally points to the in-tree v0.3 version of twilight.
This commit is contained in:
Kyle Simpson
2021-01-06 13:01:14 +00:00
committed by GitHub
parent d42e09f72b
commit f05b7414a0
14 changed files with 57 additions and 49 deletions

View File

@@ -1,7 +1,7 @@
use super::*;
use crate::events::EventData;
use flume::Sender;
use std::time::Duration;
use tokio::sync::oneshot::Sender as OneshotSender;
/// A request from external code using a [`TrackHandle`] to modify
/// or act upon an [`Track`] object.
@@ -27,7 +27,7 @@ pub enum TrackCommand {
/// Run some closure on this track, with direct access to the core object.
Do(Box<dyn FnOnce(&mut Track) + Send + Sync + 'static>),
/// Request a read-only view of this track's state.
Request(OneshotSender<Box<TrackState>>),
Request(Sender<Box<TrackState>>),
/// Change the loop count/strategy of this track.
Loop(LoopState),
/// Prompts a track's input to become live and usable, if it is not already.

View File

@@ -3,8 +3,9 @@ use crate::{
events::{Event, EventData, EventHandler},
input::Metadata,
};
use flume::Sender;
use std::{fmt, sync::Arc, time::Duration};
use tokio::sync::{mpsc::UnboundedSender, oneshot, RwLock};
use tokio::sync::RwLock;
use typemap_rev::TypeMap;
use uuid::Uuid;
@@ -25,7 +26,7 @@ pub struct TrackHandle {
}
struct InnerHandle {
command_channel: UnboundedSender<TrackCommand>,
command_channel: Sender<TrackCommand>,
seekable: bool,
uuid: Uuid,
metadata: Box<Metadata>,
@@ -50,7 +51,7 @@ impl TrackHandle {
///
/// [`Input`]: crate::input::Input
pub fn new(
command_channel: UnboundedSender<TrackCommand>,
command_channel: Sender<TrackCommand>,
seekable: bool,
uuid: Uuid,
metadata: Box<Metadata>,
@@ -159,10 +160,10 @@ impl TrackHandle {
/// Request playback information and state from the audio context.
pub async fn get_info(&self) -> TrackResult<Box<TrackState>> {
let (tx, rx) = oneshot::channel();
let (tx, rx) = flume::bounded(1);
self.send(TrackCommand::Request(tx))?;
rx.await.map_err(|_| TrackError::Finished)
rx.recv_async().await.map_err(|_| TrackError::Finished)
}
/// Set an audio track to loop indefinitely.

View File

@@ -25,8 +25,8 @@ mod state;
pub use self::{command::*, error::*, handle::*, looping::*, mode::*, queue::*, state::*};
use crate::{constants::*, driver::tasks::message::*, events::EventStore, input::Input};
use flume::{Receiver, TryRecvError};
use std::time::Duration;
use tokio::sync::mpsc::{self, error::TryRecvError, UnboundedReceiver};
use uuid::Uuid;
/// Control object for audio playback.
@@ -102,7 +102,7 @@ pub struct Track {
/// Track commands are sent in this manner to ensure that access
/// occurs in a thread-safe manner, without allowing any external
/// code to lock access to audio objects and block packet generation.
pub(crate) commands: UnboundedReceiver<TrackCommand>,
pub(crate) commands: Receiver<TrackCommand>,
/// Handle for safe control of this audio track from other threads.
///
@@ -124,11 +124,7 @@ impl Track {
/// In general, you should probably use [`create_player`].
///
/// [`create_player`]: fn.create_player.html
pub fn new_raw(
source: Input,
commands: UnboundedReceiver<TrackCommand>,
handle: TrackHandle,
) -> Self {
pub fn new_raw(source: Input, commands: Receiver<TrackCommand>, handle: TrackHandle) -> Self {
let uuid = handle.uuid();
Self {
@@ -310,7 +306,7 @@ impl Track {
MakePlayable => self.make_playable(),
}
},
Err(TryRecvError::Closed) => {
Err(TryRecvError::Disconnected) => {
// this branch will never be visited.
break;
},
@@ -389,7 +385,7 @@ pub fn create_player(source: Input) -> (Track, TrackHandle) {
/// [`Track`]: Track
/// [`TrackHandle`]: TrackHandle
pub fn create_player_with_uuid(source: Input, uuid: Uuid) -> (Track, TrackHandle) {
let (tx, rx) = mpsc::unbounded_channel();
let (tx, rx) = flume::unbounded();
let can_seek = source.is_seekable();
let metadata = source.metadata.clone();
let handle = TrackHandle::new(tx, can_seek, uuid, metadata);