diff --git a/query-engine/core/src/executor/mod.rs b/query-engine/core/src/executor/mod.rs index 43df839e9635..ba2784d3c71a 100644 --- a/query-engine/core/src/executor/mod.rs +++ b/query-engine/core/src/executor/mod.rs @@ -10,6 +10,7 @@ mod execute_operation; mod interpreting_executor; mod pipeline; mod request_context; +pub(crate) mod task; pub use self::{execute_operation::*, interpreting_executor::InterpretingExecutor}; @@ -131,66 +132,3 @@ pub trait TransactionManager { pub fn get_current_dispatcher() -> Dispatch { tracing::dispatcher::get_default(|current| current.clone()) } - -// The `task` module provides a unified interface for spawning asynchronous tasks, regardless of the target platform. -pub(crate) mod task { - pub use arch::{spawn, JoinHandle}; - use futures::Future; - - // On native targets, `tokio::spawn` spawns a new asynchronous task. - #[cfg(not(target_arch = "wasm32"))] - mod arch { - use super::*; - - pub type JoinHandle = tokio::task::JoinHandle; - - pub fn spawn(future: T) -> JoinHandle - where - T: Future + Send + 'static, - T::Output: Send + 'static, - { - tokio::spawn(future) - } - } - - // On Wasm targets, `wasm_bindgen_futures::spawn_local` spawns a new asynchronous task. - #[cfg(target_arch = "wasm32")] - mod arch { - use super::*; - use tokio::sync::oneshot::{self}; - - // Wasm-compatible alternative to `tokio::task::JoinHandle`. - // `pin_project` enables pin-projection and a `Pin`-compatible implementation of the `Future` trait. - #[pin_project::pin_project] - pub struct JoinHandle(#[pin] oneshot::Receiver); - - impl Future for JoinHandle { - type Output = Result; - - fn poll(self: std::pin::Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> std::task::Poll { - // the `self.project()` method is provided by the `pin_project` macro - let receiver: std::pin::Pin<&mut oneshot::Receiver> = self.project().0; - receiver.poll(cx) - } - } - - impl JoinHandle { - pub fn abort(&mut self) { - // abort is noop on Wasm targets - } - } - - pub fn spawn(future: T) -> JoinHandle - where - T: Future + Send + 'static, - T::Output: Send + 'static, - { - let (sender, receiver) = oneshot::channel(); - wasm_bindgen_futures::spawn_local(async move { - let result = future.await; - sender.send(result).ok(); - }); - JoinHandle(receiver) - } - } -} diff --git a/query-engine/core/src/executor/task.rs b/query-engine/core/src/executor/task.rs new file mode 100644 index 000000000000..8d1c39bbcd06 --- /dev/null +++ b/query-engine/core/src/executor/task.rs @@ -0,0 +1,59 @@ +//! This module provides a unified interface for spawning asynchronous tasks, regardless of the target platform. + +pub use arch::{spawn, JoinHandle}; +use futures::Future; + +// On native targets, `tokio::spawn` spawns a new asynchronous task. +#[cfg(not(target_arch = "wasm32"))] +mod arch { + use super::*; + + pub type JoinHandle = tokio::task::JoinHandle; + + pub fn spawn(future: T) -> JoinHandle + where + T: Future + Send + 'static, + T::Output: Send + 'static, + { + tokio::spawn(future) + } +} + +// On Wasm targets, `wasm_bindgen_futures::spawn_local` spawns a new asynchronous task. +#[cfg(target_arch = "wasm32")] +mod arch { + use super::*; + use tokio::sync::oneshot::{self}; + + // Wasm-compatible alternative to `tokio::task::JoinHandle`. + // `pin_project` enables pin-projection and a `Pin`-compatible implementation of the `Future` trait. + pub struct JoinHandle(oneshot::Receiver); + + impl Future for JoinHandle { + type Output = Result; + + fn poll(mut self: std::pin::Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> std::task::Poll { + // the `self.project()` method is provided by the `pin_project` macro + core::pin::Pin::new(&mut self.0).poll(cx) + } + } + + impl JoinHandle { + pub fn abort(&mut self) { + // abort is noop on Wasm targets + } + } + + pub fn spawn(future: T) -> JoinHandle + where + T: Future + Send + 'static, + T::Output: Send + 'static, + { + let (sender, receiver) = oneshot::channel(); + wasm_bindgen_futures::spawn_local(async move { + let result = future.await; + sender.send(result).ok(); + }); + JoinHandle(receiver) + } +}