Skip to content

Commit

Permalink
implement using tokio-process instead
Browse files Browse the repository at this point in the history
  • Loading branch information
wfraser committed Oct 16, 2018
1 parent eaac599 commit 9fa138a
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 34 deletions.
75 changes: 71 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ serde_derive = "0.9.6"
serde_json = "0.9.5"
tokio-core = "0.1.2"
tokio-io = "0.1"
tokio-process = "0.2.2"
tokio-signal = "0.1.2"
url = "1.7.0"

Expand Down
21 changes: 0 additions & 21 deletions src/child_wait_future.rs

This file was deleted.

11 changes: 4 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ extern crate log;
extern crate rpassword;
extern crate tokio_core;
extern crate tokio_io;
extern crate tokio_process;
extern crate tokio_signal;
extern crate url;

Expand Down Expand Up @@ -39,9 +40,6 @@ use librespot::playback::config::{Bitrate, PlayerConfig};
use librespot::playback::mixer::{self, Mixer};
use librespot::playback::player::{Player, PlayerEvent};

mod child_wait_future;
use child_wait_future::ChildWaitFuture;

mod player_event_handler;
use player_event_handler::run_program_on_events;

Expand Down Expand Up @@ -470,15 +468,14 @@ impl Future for Main {
if let Async::Ready(Some(event)) = player_event_channel.poll().unwrap() {
if let Some(ref program) = self.player_event_program {
let child = run_program_on_events(event, program)
.expect("program failed to start");

let wait_future = ChildWaitFuture { child }
.expect("program failed to start")
.map(|status| if !status.success() {
error!("child exited with status {:?}", status.code());
})
.map_err(|e| error!("failed to wait on child process: {}", e));

self.handle.spawn(wait_future);
self.handle.spawn(child);

}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/player_event_handler.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use librespot::playback::player::PlayerEvent;
use tokio_process::{Child, CommandExt};
use std::collections::HashMap;
use std::io;
use std::process::{Child, Command};
use std::process::Command;

fn run_program(program: &str, env_vars: HashMap<&str, String>) -> io::Result<Child> {
let mut v: Vec<&str> = program.split_whitespace().collect();
info!("Running {:?} with environment variables {:?}", v, env_vars);
Command::new(&v.remove(0))
.args(&v)
.envs(env_vars.iter())
.spawn()
.spawn_async()
}

pub fn run_program_on_events(event: PlayerEvent, onevent: &str) -> io::Result<Child> {
Expand Down

0 comments on commit 9fa138a

Please sign in to comment.