folk-api 0.1.0

Plugin contract for the Folk PHP application server
Documentation
//! The `Executor` trait — how plugins send work to PHP workers.
//!
//! `folk-core` provides the concrete implementation, backed by the worker pool.

use std::sync::Arc;

use anyhow::Result;
use async_trait::async_trait;
use bytes::Bytes;

/// Sends a serialized payload to a PHP worker and returns the response.
///
/// Plugins call this; they never see the worker pool directly.
#[async_trait]
pub trait Executor: Send + Sync + 'static {
    /// Send `payload` to a worker and return the response bytes.
    async fn execute(&self, payload: Bytes) -> Result<Bytes>;
}

/// Blanket impl: an `Arc<dyn Executor>` is also an `Executor`.
#[async_trait]
impl<T: Executor + ?Sized> Executor for Arc<T> {
    async fn execute(&self, payload: Bytes) -> Result<Bytes> {
        (**self).execute(payload).await
    }
}