product-os-server 0.0.55

Product OS : Server provides a full functioning advanced server capable of acting as a web server, command and control distributed network, authentication server, crawling server and more. Fully featured with high level of flexibility.
Documentation
//! Server executor utilities module
//!
//! This module provides utilities for spawning async tasks within the server's
//! executor context.
//!
//! # Overview
//!
//! The `ServerExecutor` struct provides a unified interface for spawning async
//! tasks regardless of the underlying executor implementation (Tokio, Embassy, etc.).
//!
//! # Usage
//!
//! The executor is used internally by the server to spawn background tasks for:
//! - HTTP/HTTPS server loops
//! - Controller operations
//! - Background services
//!
//! # Executor Abstraction
//!
//! This module abstracts over the `product_os_async_executor` traits, allowing
//! the server to work with different async runtime implementations.

use std::prelude::v1::*;

use std::sync::Arc;


/// A thin wrapper for spawning async tasks on the server's executor.
///
/// `ServerExecutor` delegates to `product_os_async_executor` to spawn futures
/// in the appropriate runtime context.
#[derive(Clone)]
pub(crate) struct ServerExecutor {}

impl ServerExecutor {
    /// Spawns a future on the given executor.
    ///
    /// # Arguments
    ///
    /// * `executor` - Arc-wrapped executor to spawn the future on
    /// * `fut` - The future to execute
    ///
    /// # Returns
    ///
    /// `Ok(())` if the task was successfully spawned, or an error string if spawning failed.
    pub fn spawn<E, X, F>(executor: Arc<E>, fut: F) -> Result<(), &'static str>
    where
        E: product_os_async_executor::Executor<X> + product_os_async_executor::ExecutorPerform<X>,
        F: core::future::Future + Send + 'static,
        F::Output: Send + 'static
    {
        E::spawn_from_executor_sync(executor.as_ref(), fut)
            .map(|_| ())
            .map_err(|_| "Failed to spawn task on executor")
    }
}