vortex_layout/scan/executor/
mod.rs1#[cfg(feature = "tokio")]
2mod tokio;
3
4mod threads;
5
6use std::future::Future;
7
8use futures::future::BoxFuture;
9pub use threads::*;
10#[cfg(feature = "tokio")]
11pub use tokio::*;
12use vortex_error::VortexResult;
13
14pub trait Executor {
15 fn spawn<F>(&self, f: F) -> BoxFuture<'static, VortexResult<F::Output>>
18 where
19 F: Future + Send + 'static,
20 <F as Future>::Output: Send + 'static;
21}
22
23#[derive(Clone)]
25pub enum TaskExecutor {
26 Threads(ThreadsExecutor),
27 #[cfg(feature = "tokio")]
28 Tokio(TokioExecutor),
29}
30
31#[async_trait::async_trait]
32impl Executor for TaskExecutor {
33 fn spawn<F>(&self, f: F) -> BoxFuture<'static, VortexResult<F::Output>>
34 where
35 F: Future + Send + 'static,
36 <F as Future>::Output: Send + 'static,
37 {
38 match self {
39 TaskExecutor::Threads(threads_executor) => threads_executor.spawn(f),
40 #[cfg(feature = "tokio")]
41 TaskExecutor::Tokio(tokio_executor) => tokio_executor.spawn(f),
42 }
43 }
44}