Skip to main content

arora_websocket/
handlers.rs

1//! Callback types the server dispatches incoming messages to.
2
3use crate::method::InvokeResult;
4use arora_types::value::Value;
5use std::collections::HashMap;
6use std::future::Future;
7use std::pin::Pin;
8use std::sync::Arc;
9
10/// Result type for the write-values handler.
11pub type WriteValuesResult = Result<(), String>;
12
13/// Handler function type for WriteValues messages.
14/// Called when an external client writes values to keys.
15pub type WriteValuesHandler =
16    Arc<dyn Fn(HashMap<String, Value>) -> WriteValuesResult + Send + Sync>;
17
18/// Handler function type for ReadValues messages.
19/// Called when an external client reads the current values of keys.
20/// Returns a map of key paths to their current values.
21pub type ReadValuesHandler = Arc<
22    dyn Fn(Vec<String>) -> Pin<Box<dyn Future<Output = HashMap<String, Value>> + Send>>
23        + Send
24        + Sync,
25>;
26
27/// Handler function type for method invocations.
28pub type MethodHandler = Arc<dyn Fn(HashMap<String, Value>) -> InvokeResult + Send + Sync>;
29
30/// Handler called when a new client connects to this connection.
31/// Receives the connection identifier (e.g., "ws://127.0.0.1:9000").
32pub type OnClientConnectedHandler = Arc<dyn Fn(String) + Send + Sync>;