switch from async-channel to crossbeam-channel

This commit is contained in:
figsoda 2020-11-19 11:54:49 -05:00
parent 8b731a60e5
commit 31239aaaba
3 changed files with 45 additions and 12 deletions

36
Cargo.lock generated
View file

@ -81,6 +81,12 @@ dependencies = [
"winapi",
]
[[package]]
name = "autocfg"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
name = "base64"
version = "0.12.3"
@ -170,6 +176,34 @@ dependencies = [
"cache-padded",
]
[[package]]
name = "const_fn"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c478836e029dcef17fb47c89023448c64f781a046e0300e257ad8225ae59afab"
[[package]]
name = "crossbeam-channel"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dca26ee1f8d361640700bde38b2c37d8c22b3ce2d360e1fc1c74ea4b0aa7d775"
dependencies = [
"cfg-if 1.0.0",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec91540d98355f690a86367e566ecad2e9e579f230230eb7c21398372be73ea5"
dependencies = [
"autocfg",
"cfg-if 1.0.0",
"const_fn",
"lazy_static",
]
[[package]]
name = "crossterm"
version = "0.18.2"
@ -371,9 +405,9 @@ name = "mmtc"
version = "0.2.4"
dependencies = [
"anyhow",
"async-channel",
"async-io",
"async-net",
"crossbeam-channel",
"crossterm",
"dirs-next",
"expand",

View file

@ -15,9 +15,9 @@ categories = ["command-line-utilities"]
[dependencies]
anyhow = "1.0.34"
async-channel = "1.5.1"
async-io = "1.2.0"
async-net = "1.5.0"
crossbeam-channel = "0.5.0"
crossterm = "0.18.2"
dirs-next = "2.0.0"
expand = "0.2.0"

View file

@ -10,8 +10,8 @@ mod layout;
mod mpd;
use anyhow::{Context, Error, Result};
use async_channel::bounded;
use async_io::{block_on, Timer};
use crossbeam_channel::unbounded;
use crossterm::{
event::{
self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEvent, KeyModifiers,
@ -131,7 +131,7 @@ async fn run() -> Result<()> {
let seek_forwards = seek_forwards.as_bytes();
let update_interval = Duration::from_secs_f32(1.0 / opts.ups.unwrap_or(cfg.ups));
let (tx, rx) = bounded(32);
let (tx, rx) = unbounded();
let tx1 = tx.clone();
let tx2 = tx.clone();
let tx3 = tx.clone();
@ -141,12 +141,12 @@ async fn run() -> Result<()> {
loop {
let changed = idle_cl.idle().await.unwrap_or_else(die);
if changed.0 {
tx.send(Command::UpdateStatus).await.unwrap_or_else(die);
tx.send(Command::UpdateStatus).unwrap_or_else(die);
}
if changed.1 {
tx.send(Command::UpdateQueue).await.unwrap_or_else(die);
tx.send(Command::UpdateQueue).unwrap_or_else(die);
}
tx.send(Command::UpdateFrame).await.unwrap_or_else(die);
tx.send(Command::UpdateFrame).unwrap_or_else(die);
}
});
@ -154,8 +154,8 @@ async fn run() -> Result<()> {
let tx = tx2;
loop {
let timer = Timer::after(update_interval);
tx.send(Command::UpdateStatus).await.unwrap_or_else(die);
tx.send(Command::UpdateFrame).await.unwrap_or_else(die);
tx.send(Command::UpdateStatus).unwrap_or_else(die);
tx.send(Command::UpdateFrame).unwrap_or_else(die);
timer.await;
}
});
@ -217,12 +217,11 @@ async fn run() -> Result<()> {
},
_ => continue,
})
.await
.unwrap_or_else(die);
}
});
while let Ok(cmd) = rx.recv().await {
while let Ok(cmd) = rx.recv() {
match cmd {
Command::Quit => break,
Command::UpdateFrame => render(&mut term, &cfg.layout, &mut s)?,
@ -353,7 +352,7 @@ async fn run() -> Result<()> {
.context("Failed to play the selected song")?;
s.status = cl.status().await?;
if clear_query_on_play {
tx.send(Command::QuitSearch).await?;
tx.send(Command::QuitSearch)?;
} else {
render(&mut term, &cfg.layout, &mut s)?;
}