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