Skip to main content

karyon_jsonrpc/
hyper_exec.rs

1//! `hyper::rt::Executor` impl shared by the HTTP server and the
2//! tokio HTTP/1+2 client. Spawns hyper's internal tasks via the
3//! owning Server/Client task_group so they get cancelled on stop.
4
5use std::sync::Arc;
6
7use karyon_core::async_util::{TaskGroup, TaskResult};
8
9#[derive(Clone)]
10pub(crate) struct HyperExecutor {
11    task_group: Arc<TaskGroup>,
12}
13
14impl HyperExecutor {
15    pub(crate) fn new(task_group: Arc<TaskGroup>) -> Self {
16        Self { task_group }
17    }
18}
19
20impl<F> hyper::rt::Executor<F> for HyperExecutor
21where
22    F: std::future::Future + Send + 'static,
23    F::Output: Send + 'static,
24{
25    fn execute(&self, fut: F) {
26        self.task_group.spawn(
27            async move {
28                let _ = fut.await;
29            },
30            |_: TaskResult<()>| async {},
31        );
32    }
33}