signal: Change constructors to return a result instead of lazy future (#1340)

This commit is contained in:
Ivan Petkov
2019-07-30 18:23:26 -07:00
committed by GitHub
parent bf38631d6a
commit ff922bbe6d
18 changed files with 86 additions and 143 deletions
+3 -11
View File
@@ -35,11 +35,7 @@ use self::orphan::{AtomicOrphanQueue, OrphanQueue, Wait};
use self::reap::Reaper;
use super::SpawnedChild;
use crate::kill::Kill;
use futures_core::stream::Stream;
use futures_util::future;
use futures_util::future::FutureExt;
use futures_util::stream::StreamExt;
use futures_util::try_future::TryFutureExt;
use std::fmt;
use std::future::Future;
use std::io;
@@ -89,11 +85,9 @@ impl OrphanQueue<process::Child> for GlobalOrphanQueue {
}
}
type ChildReaperFuture = Pin<Box<dyn Stream<Item = io::Result<()>> + Send>>;
#[must_use = "futures do nothing unless polled"]
pub struct Child {
inner: Reaper<process::Child, GlobalOrphanQueue, ChildReaperFuture>,
inner: Reaper<process::Child, GlobalOrphanQueue, Signal>,
}
impl fmt::Debug for Child {
@@ -110,10 +104,8 @@ pub(crate) fn spawn_child(cmd: &mut process::Command, handle: &Handle) -> io::Re
let stdout = stdio(child.stdout.take(), handle)?;
let stderr = stdio(child.stderr.take(), handle)?;
let signal = Signal::with_handle(libc::SIGCHLD, handle)
.and_then(|stream| future::ok(stream.map(Ok)))
.try_flatten_stream()
.boxed();
let signal = Signal::with_handle(libc::SIGCHLD, handle)?;
Ok(SpawnedChild {
child: Child {
inner: Reaper::new(child, GlobalOrphanQueue, signal),
+6 -12
View File
@@ -1,7 +1,6 @@
use super::orphan::{OrphanQueue, Wait};
use crate::kill::Kill;
use futures_core::stream::TryStream;
use futures_util::try_stream::TryStreamExt;
use futures_core::stream::Stream;
use std::future::Future;
use std::io;
use std::ops::Deref;
@@ -61,12 +60,11 @@ impl<W, Q, S> Future for Reaper<W, Q, S>
where
W: Wait + Unpin,
Q: OrphanQueue<W> + Unpin,
S: TryStream<Error = io::Error> + Unpin,
S: Stream + Unpin,
{
type Output = io::Result<ExitStatus>;
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
let inner = Pin::get_mut(self);
fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
loop {
// If the child hasn't exited yet, then it's our responsibility to
// ensure the current task gets notified when it might be able to
@@ -87,14 +85,10 @@ where
// this future's task will be notified/woken up again. Since the
// futures model allows for spurious wake ups this extra wakeup
// should not cause significant issues with parent futures.
let signal_poll = inner.signal.try_poll_next_unpin(cx);
if let Poll::Ready(Some(Err(err))) = signal_poll {
return Poll::Ready(Err(err));
}
let registered_interest = signal_poll.is_pending();
let registered_interest = Pin::new(&mut self.signal).poll_next(cx).is_pending();
inner.orphan_queue.reap_orphans();
if let Some(status) = inner.inner_mut().try_wait()? {
self.orphan_queue.reap_orphans();
if let Some(status) = self.inner_mut().try_wait()? {
return Poll::Ready(Ok(status));
}
-1
View File
@@ -13,7 +13,6 @@ use std::process::{Command, ExitStatus, Stdio};
use futures_util::future;
use futures_util::future::FutureExt;
use futures_util::io::AsyncBufReadExt;
use futures_util::io::AsyncReadExt;
use futures_util::io::AsyncWriteExt;
use futures_util::io::BufReader;
use futures_util::stream::{self, StreamExt};