folk-api 0.1.2

Plugin contract for the Folk PHP application server
Documentation
//! Dependencies handed to a plugin at boot.

use std::sync::Arc;

use tokio::sync::watch;

use crate::executor::Executor;
use crate::health::HealthRegistry;
use crate::metrics::MetricsRegistry;
use crate::rpc::RpcRegistrar;

/// What every plugin receives in [`Plugin::boot`](crate::Plugin::boot).
///
/// All fields are cheaply cloneable (`Arc` or `Receiver`).
#[derive(Clone)]
pub struct PluginContext {
    /// Send work to a PHP worker.
    pub executor: Arc<dyn Executor>,

    /// Fires `true` when the server is shutting down.
    pub shutdown: watch::Receiver<bool>,

    /// Register RPC method handlers. `None` if not available.
    pub rpc_registrar: Option<Arc<dyn RpcRegistrar>>,

    /// Register health checks. `None` if not available.
    pub health_registry: Option<Arc<dyn HealthRegistry>>,

    /// Register metrics. `None` if not available.
    pub metrics_registry: Option<Arc<dyn MetricsRegistry>>,
}