mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-24 00:00:11 +02:00
process: Remove dependency on tokio-core
This commit is contained in:
+1
-1
@@ -18,13 +18,13 @@ appveyor = { repository = "alexcrichton/tokio-process" }
|
||||
[dependencies]
|
||||
futures = "0.1.11"
|
||||
mio = "0.6.5"
|
||||
tokio-core = "0.1.6"
|
||||
tokio-io = "0.1"
|
||||
tokio-reactor = "0.1"
|
||||
|
||||
[dev-dependencies]
|
||||
env_logger = { version = "0.4", default-features = false }
|
||||
log = "0.4"
|
||||
tokio = "0.1"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
mio-named-pipes = "0.1"
|
||||
|
||||
+31
-31
@@ -14,31 +14,27 @@
|
||||
//!
|
||||
//! ```no_run
|
||||
//! extern crate futures;
|
||||
//! extern crate tokio_core;
|
||||
//! extern crate tokio;
|
||||
//! extern crate tokio_process;
|
||||
//!
|
||||
//! use std::process::Command;
|
||||
//!
|
||||
//! use futures::Future;
|
||||
//! use tokio_core::reactor::Core;
|
||||
//! use tokio_process::CommandExt;
|
||||
//!
|
||||
//! fn main() {
|
||||
//! // Create our own local event loop
|
||||
//! let mut core = Core::new().unwrap();
|
||||
//!
|
||||
//! // Use the standard library's `Command` type to build a process and
|
||||
//! // then execute it via the `CommandExt` trait.
|
||||
//! let child = Command::new("echo").arg("hello").arg("world")
|
||||
//! .spawn_async_with_handle(core.handle().new_tokio_handle());
|
||||
//! .spawn_async();
|
||||
//!
|
||||
//! // Make sure our child succeeded in spawning
|
||||
//! let child = child.expect("failed to spawn");
|
||||
//! // Make sure our child succeeded in spawning and process the result
|
||||
//! let future = child.expect("failed to spawn")
|
||||
//! .map(|status| println!("exit status: {}", status))
|
||||
//! .map_err(|e| panic!("failed to wait for exit: {}", e));
|
||||
//!
|
||||
//! match core.run(child) {
|
||||
//! Ok(status) => println!("exit status: {}", status),
|
||||
//! Err(e) => panic!("failed to wait for exit: {}", e),
|
||||
//! }
|
||||
//! // Send the future to the tokio runtime for execution
|
||||
//! tokio::run(future)
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
@@ -47,26 +43,27 @@
|
||||
//!
|
||||
//! ```no_run
|
||||
//! extern crate futures;
|
||||
//! extern crate tokio_core;
|
||||
//! extern crate tokio;
|
||||
//! extern crate tokio_process;
|
||||
//!
|
||||
//! use std::process::Command;
|
||||
//!
|
||||
//! use futures::Future;
|
||||
//! use tokio_core::reactor::Core;
|
||||
//! use tokio_process::CommandExt;
|
||||
//!
|
||||
//! fn main() {
|
||||
//! let mut core = Core::new().unwrap();
|
||||
//!
|
||||
//! // Like above, but use `output_async` which returns a future instead of
|
||||
//! // immediately returning the `Child`.
|
||||
//! let output = Command::new("echo").arg("hello").arg("world")
|
||||
//! .output_async_with_handle(core.handle().new_tokio_handle());
|
||||
//! let output = core.run(output).expect("failed to collect output");
|
||||
//! .output_async();
|
||||
//!
|
||||
//! assert!(output.status.success());
|
||||
//! assert_eq!(output.stdout, b"hello world\n");
|
||||
//! let future = output.map_err(|e| panic!("failed to collect output: {}", e))
|
||||
//! .map(|output| {
|
||||
//! assert!(output.status.success());
|
||||
//! assert_eq!(output.stdout, b"hello world\n");
|
||||
//! });
|
||||
//!
|
||||
//! tokio::run(future);
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
@@ -74,18 +71,17 @@
|
||||
//!
|
||||
//! ```no_run
|
||||
//! extern crate futures;
|
||||
//! extern crate tokio_core;
|
||||
//! extern crate tokio;
|
||||
//! extern crate tokio_process;
|
||||
//! extern crate tokio_io;
|
||||
//!
|
||||
//! use std::io;
|
||||
//! use std::process::{Command, Stdio, ExitStatus};
|
||||
//! use std::process::{Command, Stdio};
|
||||
//!
|
||||
//! use futures::{BoxFuture, Future, Stream};
|
||||
//! use tokio_core::reactor::Core;
|
||||
//! use futures::{Future, Stream};
|
||||
//! use tokio_process::{CommandExt, Child};
|
||||
//!
|
||||
//! fn print_lines(mut cat: Child) -> BoxFuture<ExitStatus, io::Error> {
|
||||
//! fn print_lines(mut cat: Child) -> Box<Future<Item = (), Error = ()> + Send + 'static> {
|
||||
//! let stdout = cat.stdout().take().unwrap();
|
||||
//! let reader = io::BufReader::new(stdout);
|
||||
//! let lines = tokio_io::io::lines(reader);
|
||||
@@ -93,15 +89,20 @@
|
||||
//! println!("Line: {}", l);
|
||||
//! Ok(())
|
||||
//! });
|
||||
//! cycle.join(cat).map(|((), s)| s).boxed()
|
||||
//!
|
||||
//! let future = cycle.join(cat)
|
||||
//! .map(|_| ())
|
||||
//! .map_err(|e| panic!("{}", e));
|
||||
//!
|
||||
//! Box::new(future)
|
||||
//! }
|
||||
//!
|
||||
//! fn main() {
|
||||
//! let mut core = Core::new().unwrap();
|
||||
//! let mut cmd = Command::new("cat");
|
||||
//! let mut cat = cmd.stdout(Stdio::piped());
|
||||
//! let child = cat.spawn_async_with_handle(core.handle().new_tokio_handle()).unwrap();
|
||||
//! core.run(print_lines(child)).unwrap();
|
||||
//! cmd.stdout(Stdio::piped());
|
||||
//!
|
||||
//! let future = print_lines(cmd.spawn_async().expect("failed to spawn command"));
|
||||
//! tokio::run(future);
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
@@ -120,7 +121,6 @@
|
||||
#![doc(html_root_url = "https://docs.rs/tokio-process/0.1")]
|
||||
|
||||
extern crate futures;
|
||||
extern crate tokio_core;
|
||||
extern crate tokio_io;
|
||||
extern crate tokio_reactor;
|
||||
extern crate mio;
|
||||
|
||||
+8
-5
@@ -1,21 +1,24 @@
|
||||
extern crate tokio_core;
|
||||
extern crate tokio;
|
||||
extern crate tokio_process;
|
||||
|
||||
use tokio_core::reactor::Core;
|
||||
use tokio::executor::current_thread;
|
||||
use tokio_process::CommandExt;
|
||||
|
||||
mod support;
|
||||
|
||||
#[test]
|
||||
fn simple() {
|
||||
let mut lp = Core::new().unwrap();
|
||||
let mut cmd = support::cmd("exit");
|
||||
cmd.arg("2");
|
||||
let mut child = cmd.spawn_async_with_handle(lp.handle().new_tokio_handle()).unwrap();
|
||||
|
||||
let mut child = cmd.spawn_async().unwrap();
|
||||
|
||||
let id = child.id();
|
||||
assert!(id > 0);
|
||||
let status = lp.run(&mut child).unwrap();
|
||||
|
||||
let status = current_thread::block_on_all(&mut child).unwrap();
|
||||
assert_eq!(status.code(), Some(2));
|
||||
|
||||
assert_eq!(child.id(), id);
|
||||
drop(child.kill());
|
||||
}
|
||||
|
||||
+23
-23
@@ -1,5 +1,5 @@
|
||||
extern crate futures;
|
||||
extern crate tokio_core;
|
||||
extern crate tokio;
|
||||
extern crate tokio_io;
|
||||
extern crate tokio_process;
|
||||
#[macro_use]
|
||||
@@ -9,12 +9,14 @@ extern crate env_logger;
|
||||
use std::io;
|
||||
use std::process::{Stdio, ExitStatus, Command};
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
|
||||
use futures::future::Future;
|
||||
use futures::stream::{self, Stream};
|
||||
use tokio::executor::current_thread;
|
||||
use tokio_io::io::{read_until, write_all, read_to_end};
|
||||
use tokio_core::reactor::{Core, Timeout};
|
||||
use tokio_process::{CommandExt, Child};
|
||||
use tokio::timer::Deadline;
|
||||
|
||||
mod support;
|
||||
|
||||
@@ -84,34 +86,35 @@ fn feed_cat(mut cat: Child, n: usize) -> Box<Future<Item = ExitStatus, Error = i
|
||||
///
|
||||
/// - The child does produce EOF on stdout after the last line.
|
||||
fn feed_a_lot() {
|
||||
let mut lp = Core::new().unwrap();
|
||||
let child = cat().spawn_async_with_handle(lp.handle().new_tokio_handle()).unwrap();
|
||||
let status = lp.run(feed_cat(child, 10000)).unwrap();
|
||||
let child = cat().spawn_async().unwrap();
|
||||
let status = current_thread::block_on_all(feed_cat(child, 10000)).unwrap();
|
||||
assert_eq!(status.code(), Some(0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn drop_kills() {
|
||||
let mut lp = Core::new().unwrap();
|
||||
let mut child = cat().spawn_async_with_handle(lp.handle().new_tokio_handle()).unwrap();
|
||||
let mut child = cat().spawn_async().unwrap();
|
||||
let stdin = child.stdin().take().unwrap();
|
||||
let stdout = child.stdout().take().unwrap();
|
||||
drop(child);
|
||||
|
||||
drop(lp.run(write_all(stdin, b"1234")));
|
||||
let (_, output) = lp.run(read_to_end(stdout, Vec::new())).unwrap();
|
||||
// Ignore all write errors since we expect a broken pipe here
|
||||
let writer = write_all(stdin, b"1234").then(|_| Ok(()));
|
||||
let reader = read_to_end(stdout, Vec::new());
|
||||
|
||||
let future = writer.join(reader).map(|(_, (_, out))| out);
|
||||
|
||||
let output = current_thread::block_on_all(future).unwrap();
|
||||
assert_eq!(output.len(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wait_with_output_captures() {
|
||||
let mut core = Core::new().unwrap();
|
||||
|
||||
let mut child = cat().spawn_async_with_handle(core.handle().new_tokio_handle()).unwrap();
|
||||
let mut child = cat().spawn_async().unwrap();
|
||||
let stdin = child.stdin().take().unwrap();
|
||||
let out = child.wait_with_output();
|
||||
|
||||
let ret = core.run(write_all(stdin, b"1234").map(|p| p.1).join(out)).unwrap();
|
||||
let ret = current_thread::block_on_all(write_all(stdin, b"1234").map(|p| p.1).join(out)).unwrap();
|
||||
let (written, output) = ret;
|
||||
|
||||
assert!(output.status.success());
|
||||
@@ -121,18 +124,15 @@ fn wait_with_output_captures() {
|
||||
|
||||
#[test]
|
||||
fn status_closes_any_pipes() {
|
||||
let mut core = Core::new().unwrap();
|
||||
|
||||
// Cat will open a pipe between the parent and child.
|
||||
// If `status_async` doesn't ensure the handles are closed,
|
||||
// we would end up blocking forever (and time out).
|
||||
let child = cat().status_async_with_handle(core.handle().new_tokio_handle()).unwrap();
|
||||
let timeout = Timeout::new(Duration::from_secs(1), &core.handle())
|
||||
.expect("timeout registration failed")
|
||||
.map(|()| panic!("time out exceeded! did we get stuck waiting on the child?"));
|
||||
let child = cat().status_async().expect("failed to spawn child");
|
||||
|
||||
match core.run(child.select(timeout)) {
|
||||
Ok((status, _)) => assert!(status.success()),
|
||||
Err(_) => panic!("failed to run futures"),
|
||||
}
|
||||
// NB: Deadline requires a timer registration which is provided by
|
||||
// tokio's `current_thread::Runtime`, but isn't available by just using
|
||||
// tokio's default CurrentThread executor which powers `current_thread::block_on_all`.
|
||||
let mut rt = tokio::runtime::current_thread::Runtime::new().unwrap();
|
||||
rt.block_on(Deadline::new(child, Instant::now() + Duration::from_secs(1)))
|
||||
.expect("time out exceeded! did we get stuck waiting on the child?");
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
extern crate env_logger;
|
||||
extern crate futures;
|
||||
extern crate tokio_core;
|
||||
extern crate tokio_process;
|
||||
|
||||
use std::env;
|
||||
|
||||
Reference in New Issue
Block a user