diff --git a/lib/cli/src/commands/run/mod.rs b/lib/cli/src/commands/run/mod.rs index 132042c31ab..37cfe27e9a0 100644 --- a/lib/cli/src/commands/run/mod.rs +++ b/lib/cli/src/commands/run/mod.rs @@ -217,7 +217,7 @@ impl Run { .spawn_and_block_on(async move { BinaryPackage::from_registry(&specifier, inner_runtime.as_ref()).await }) - .with_context(|| format!("Unable to load \"{name}\""))? + .with_context(|| format!("Unable to load \"{name}\""))?? }; dependencies.push(pkg); } @@ -574,7 +574,7 @@ impl PackageSource { let inner_rt = rt.clone(); let pkg = rt.task_manager().spawn_and_block_on(async move { BinaryPackage::from_registry(&inner_pck, inner_rt.as_ref()).await - })?; + })??; Ok(ExecutableTarget::Package(pkg)) } } @@ -667,7 +667,7 @@ impl ExecutableTarget { let inner_runtime = runtime.clone(); let pkg = runtime.task_manager().spawn_and_block_on(async move { BinaryPackage::from_webc(&container, inner_runtime.as_ref()).await - })?; + })??; Ok(ExecutableTarget::Package(pkg)) } @@ -718,7 +718,7 @@ impl ExecutableTarget { let inner_runtime = runtime.clone(); let pkg = runtime.task_manager().spawn_and_block_on(async move { BinaryPackage::from_webc(&container, inner_runtime.as_ref()).await - })?; + })??; Ok(ExecutableTarget::Package(pkg)) } } diff --git a/lib/cli/src/commands/run/wasi.rs b/lib/cli/src/commands/run/wasi.rs index 2cbbd0ecb7a..a631a9a3450 100644 --- a/lib/cli/src/commands/run/wasi.rs +++ b/lib/cli/src/commands/run/wasi.rs @@ -237,7 +237,7 @@ impl Wasi { .spawn_and_block_on(async move { BinaryPackage::from_registry(&specifier, &*inner_rt).await }) - .with_context(|| format!("Unable to load \"{name}\""))? + .with_context(|| format!("Unable to load \"{name}\""))?? }; uses.push(pkg); } diff --git a/lib/wasix/src/runners/wasi.rs b/lib/wasix/src/runners/wasi.rs index 1493feb3d5f..fb7fcb5d2e6 100644 --- a/lib/wasix/src/runners/wasi.rs +++ b/lib/wasix/src/runners/wasi.rs @@ -377,7 +377,7 @@ impl crate::runners::Runner for WasiRunner { .context("Unable to wait for the process to exit") } .in_current_span(), - )?; + )??; if exit_code.raw() == 0 { Ok(()) diff --git a/lib/wasix/src/runners/wcgi/runner.rs b/lib/wasix/src/runners/wcgi/runner.rs index 529181cde07..b814694fefe 100644 --- a/lib/wasix/src/runners/wcgi/runner.rs +++ b/lib/wasix/src/runners/wcgi/runner.rs @@ -150,7 +150,7 @@ impl WcgiRunner { }) .await }) - .context("Unable to start the server")?; + .context("Unable to start the server")??; Ok(()) } diff --git a/lib/wasix/src/runtime/task_manager/mod.rs b/lib/wasix/src/runtime/task_manager/mod.rs index b42be6784aa..b55e0701c4a 100644 --- a/lib/wasix/src/runtime/task_manager/mod.rs +++ b/lib/wasix/src/runtime/task_manager/mod.rs @@ -402,7 +402,10 @@ impl dyn VirtualTaskManager { pub trait VirtualTaskManagerExt { /// Runs the work in the background via the task managers shared background /// threads while blocking the current execution until it finishs - fn spawn_and_block_on(&self, task: impl Future + Send + 'static) -> A + fn spawn_and_block_on( + &self, + task: impl Future + Send + 'static, + ) -> Result where A: Send + 'static; @@ -422,17 +425,21 @@ where { /// Runs the work in the background via the task managers shared background /// threads while blocking the current execution until it finishs - fn spawn_and_block_on(&self, task: impl Future + Send + 'static) -> A + fn spawn_and_block_on( + &self, + task: impl Future + Send + 'static, + ) -> Result where A: Send + 'static, { - let (work_tx, mut work_rx) = ::tokio::sync::mpsc::unbounded_channel(); + let (tx, rx) = ::tokio::sync::oneshot::channel(); let work = Box::pin(async move { let ret = task.await; - work_tx.send(ret).ok(); + tx.send(ret).ok(); }); self.task_shared(Box::new(move || work)).unwrap(); - InlineWaker::block_on(work_rx.recv()).unwrap() + rx.blocking_recv() + .map_err(|_| anyhow::anyhow!("task execution failed - result channel dropped")) } fn spawn_await(