Skip to main content

folk_api/
executor.rs

1//! The `Executor` trait — how plugins send work to PHP workers.
2//!
3//! `folk-core` provides the concrete implementation, backed by the worker pool.
4
5use std::sync::Arc;
6
7use anyhow::Result;
8use async_trait::async_trait;
9use bytes::Bytes;
10
11/// Sends a serialized payload to a PHP worker and returns the response.
12///
13/// Plugins call this; they never see the worker pool directly.
14#[async_trait]
15pub trait Executor: Send + Sync + 'static {
16    /// Send `payload` to a worker and return the response bytes.
17    async fn execute(&self, payload: Bytes) -> Result<Bytes>;
18}
19
20/// Blanket impl: an `Arc<dyn Executor>` is also an `Executor`.
21#[async_trait]
22impl<T: Executor + ?Sized> Executor for Arc<T> {
23    async fn execute(&self, payload: Bytes) -> Result<Bytes> {
24        (**self).execute(payload).await
25    }
26}