wasmer_wasix/runners/wcgi/
callbacks.rs1use std::{collections::HashMap, sync::Arc};
2
3use virtual_fs::Pipe;
4use wasmer::{Memory, Module, Store};
5
6use super::{create_env::default_recycle_env, handler::SetupBuilder, *};
7use crate::WasiEnv;
8use wasmer_types::ModuleHash;
9
10pub struct CreateEnvConfig {
12 pub env: HashMap<String, String>,
13 pub program_name: String,
14 pub module: Module,
15 pub module_hash: ModuleHash,
16 pub runtime: Arc<dyn crate::runtime::Runtime + Send + Sync>,
17 pub setup_builder: SetupBuilder,
18}
19
20pub struct CreateEnvResult {
22 pub env: WasiEnv,
23 pub memory: Option<(Memory, Store)>,
24 pub body_sender: Pipe,
25 pub body_receiver: Pipe,
26 pub stderr_receiver: Pipe,
27}
28
29pub struct RecycleEnvConfig {
31 pub env: WasiEnv,
32 pub memory: Memory,
33 pub store: Store,
34}
35
36#[async_trait::async_trait]
39pub trait Callbacks: std::fmt::Debug + Send + Sync + 'static {
40 fn started(&self, _abort: AbortHandle) {}
42
43 fn on_stderr(&self, _stderr: &[u8]) {}
45
46 fn on_stderr_error(&self, _error: std::io::Error) {}
48
49 async fn recycle_env(&self, conf: RecycleEnvConfig) {
51 default_recycle_env(conf).await
52 }
53
54 async fn create_env(&self, conf: CreateEnvConfig) -> anyhow::Result<CreateEnvResult> {
56 default_create_env(conf).await
57 }
58}
59
60#[derive(Debug)]
61pub struct NoOpWcgiCallbacks;
62
63impl Callbacks for NoOpWcgiCallbacks {}