diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-02-27 21:08:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-27 21:08:21 +0100 |
commit | fa5f3aa600311000cee0a4c794f85d48e6397362 (patch) | |
tree | c7219b232716c5bd850c4e19708d89d0d9739e41 /cli/ops/process.rs | |
parent | ff4b7b0921760f97e83ec34435f875e074f3d069 (diff) |
replace impl Future with poll_fn for net.rs, process.rs, tls.rs (#4158)
Diffstat (limited to 'cli/ops/process.rs')
-rw-r--r-- | cli/ops/process.rs | 45 |
1 files changed, 13 insertions, 32 deletions
diff --git a/cli/ops/process.rs b/cli/ops/process.rs index 82ac25bbe..ad6a022bf 100644 --- a/cli/ops/process.rs +++ b/cli/ops/process.rs @@ -6,15 +6,11 @@ use crate::signal::kill; use crate::state::State; use deno_core::*; use futures; +use futures::future::poll_fn; use futures::future::FutureExt; -use futures::future::TryFutureExt; +use futures::TryFutureExt; use std; use std::convert::From; -use std::future::Future; -use std::pin::Pin; -use std::process::ExitStatus; -use std::task::Context; -use std::task::Poll; use tokio::process::Command; #[cfg(unix)] @@ -172,26 +168,6 @@ fn op_run( }))) } -pub struct ChildStatus { - rid: ResourceId, - state: State, -} - -impl Future for ChildStatus { - type Output = Result<ExitStatus, OpError>; - - fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> { - let inner = self.get_mut(); - let mut state = inner.state.borrow_mut(); - let child_resource = state - .resource_table - .get_mut::<ChildResource>(inner.rid) - .ok_or_else(OpError::bad_resource)?; - let child = &mut child_resource.child; - child.map_err(OpError::from).poll_unpin(cx) - } -} - #[derive(Deserialize)] #[serde(rename_all = "camelCase")] struct RunStatusArgs { @@ -207,14 +183,19 @@ fn op_run_status( let rid = args.rid as u32; state.check_run()?; - - let future = ChildStatus { - rid, - state: state.clone(), - }; + let state = state.clone(); let future = async move { - let run_status = future.await?; + let run_status = poll_fn(|cx| { + let resource_table = &mut state.borrow_mut().resource_table; + let child_resource = resource_table + .get_mut::<ChildResource>(rid) + .ok_or_else(OpError::bad_resource)?; + let child = &mut child_resource.child; + child.map_err(OpError::from).poll_unpin(cx) + }) + .await?; + let code = run_status.code(); #[cfg(unix)] |