mirror of
https://github.com/figsoda/mmtc
synced 2024-11-10 18:24:13 +00:00
prevent resolving addresss multiple times
This commit is contained in:
parent
a43bd5bd28
commit
28cb05b78d
1 changed files with 8 additions and 11 deletions
19
src/main.rs
19
src/main.rs
|
@ -10,6 +10,7 @@ mod mpd;
|
|||
|
||||
use anyhow::{Context, Result};
|
||||
use async_io::{block_on, Timer};
|
||||
use async_net::resolve;
|
||||
use clap::Clap;
|
||||
use crossbeam_queue::SegQueue;
|
||||
use crossterm::{
|
||||
|
@ -84,21 +85,17 @@ async fn run() -> Result<()> {
|
|||
defaults::config()
|
||||
};
|
||||
|
||||
let (mut idle_cl, mut cl) = if let Some(addr) = opts.address {
|
||||
let idle_cl = Client::init(addr).await?;
|
||||
let cl = Client::init(addr).await?;
|
||||
(idle_cl, cl)
|
||||
let addr = &*if let Some(addr) = opts.address {
|
||||
resolve(addr).await?
|
||||
} else if let (Ok(host), Ok(port)) = (env::var("MPD_HOST"), env::var("MPD_PORT")) {
|
||||
let addr = &*async_net::resolve((host, port.parse()?)).await?;
|
||||
let idle_cl = Client::init(addr).await?;
|
||||
let cl = Client::init(addr).await?;
|
||||
(idle_cl, cl)
|
||||
resolve((host, port.parse()?)).await?
|
||||
} else {
|
||||
let idle_cl = Client::init(&cfg.address).await?;
|
||||
let cl = Client::init(&cfg.address).await?;
|
||||
(idle_cl, cl)
|
||||
resolve(cfg.address).await?
|
||||
};
|
||||
|
||||
let mut idle_cl = Client::init(addr).await?;
|
||||
let mut cl = Client::init(addr).await?;
|
||||
|
||||
let status = cl.status().await?;
|
||||
let (queue, mut queue_strings) = idle_cl.queue(status.queue_len, &cfg.search_fields).await?;
|
||||
let mut s = State {
|
||||
|
|
Loading…
Reference in a new issue