Mountain/RPC/EchoAction/
EchoActionServer.rs1
2use std::sync::Arc;
6
7use Echo::{Scheduler::Scheduler::Scheduler, Task::Priority::Priority as EchoPriority};
8use tokio::sync::oneshot;
9
10use crate::RPC::EchoAction::{ExtensionHostRegistry, ResolveMethodPriority};
11
12#[derive(Clone)]
13pub struct Struct {
14 Registry:Arc<ExtensionHostRegistry::Struct>,
15}
16
17impl Default for Struct {
18 fn default() -> Self { Self::new() }
19}
20
21impl Struct {
22 pub fn new() -> Self { Self { Registry:Arc::new(ExtensionHostRegistry::Struct::new()) } }
23
24 pub fn Registry(&self) -> Arc<ExtensionHostRegistry::Struct> { self.Registry.clone() }
27
28 pub async fn Dispatch<F, T>(&self, Scheduler:&Scheduler, Method:&str, Task:F) -> Result<T, String>
31 where
32 F: std::future::Future<Output = T> + Send + 'static,
33 T: Send + 'static, {
34 let Priority = ResolveMethodPriority::Fn(Method);
35
36 let (Sender, Receiver) = oneshot::channel::<T>();
37
38 Scheduler.Submit(
39 async move {
40 let Output = Task.await;
41 let _ = Sender.send(Output);
42 },
43 Priority,
44 );
45
46 Receiver
47 .await
48 .map_err(|_| "EchoAction task cancelled before completion".to_string())
49 }
50}
51
52#[allow(dead_code)]
55fn _Priority(P:EchoPriority) -> EchoPriority { P }