1use futures::FutureExt;
2use std::pin::Pin;
3
4pub trait Executor {
5 #[track_caller]
6 fn exec(&self, future: Pin<Box<dyn Future<Output = ()> + Send>>);
7}
8
9pub struct ExecSwitch(Box<dyn Executor + Send>);
10
11impl ExecSwitch {
12 pub fn boxed<T>(executor: T) -> Self
13 where
14 T: Executor + Send + 'static,
15 {
16 ExecSwitch(Box::new(executor))
17 }
18
19 pub fn new(executor: Box<dyn Executor + Send>) -> Self {
20 ExecSwitch(executor)
21 }
22
23 pub fn spawn(&mut self, task: impl Future<Output = ()> + Send + 'static) {
24 self.0.exec(task.boxed());
25 }
26}