Common/IPC/
SendRequestToSideCar.rs

1//! # SendRequestToSideCar Effect
2//!
3//! Defines the `ActionEffect` for sending a request-response RPC call to a
4//! sidecar process.
5
6use std::sync::Arc;
7
8use serde_json::Value;
9
10use super::IPCProvider::IPCProvider;
11use crate::{Effect::ActionEffect::ActionEffect, Error::CommonError::CommonError};
12
13/// Creates an effect that, when executed, will send a request to a specified
14/// sidecar process and await its response.
15///
16/// It uses the `IPCProvider` capability from the environment to perform the
17/// actual IPC request operation over the underlying transport (e.g., gRPC).
18///
19/// # Parameters
20///
21/// * `SideCarIdentifier`: The unique ID of the target sidecar process.
22/// * `Method`: The name of the RPC method to be invoked on the sidecar.
23/// * `Parameters`: A `serde_json::Value` containing the parameters for the
24///   request.
25/// * `TimeoutMilliseconds`: The maximum time to wait for a response before
26///   failing.
27///
28/// # Returns
29///
30/// An `ActionEffect` that resolves with the `serde_json::Value` response from
31/// the sidecar.
32pub fn SendRequestToSideCar(
33	SideCarIdentifier:String,
34
35	Method:String,
36
37	Parameters:Value,
38
39	TimeoutMilliseconds:u64,
40) -> ActionEffect<Arc<dyn IPCProvider>, CommonError, Value> {
41	ActionEffect::New(Arc::new(move |Provider:Arc<dyn IPCProvider>| {
42		let SideCarIdentifierClone = SideCarIdentifier.clone();
43
44		let MethodClone = Method.clone();
45
46		let ParametersClone = Parameters.clone();
47
48		Box::pin(async move {
49			Provider
50				.SendRequestToSideCar(SideCarIdentifierClone, MethodClone, ParametersClone, TimeoutMilliseconds)
51				.await
52		})
53	}))
54}