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 let (Sender, Receiver) = oneshot::channel::<T>();
37 Scheduler.Submit(
38 async move {
39 let Output = Task.await;
40 let _ = Sender.send(Output);
41 },
42 Priority,
43 );
44 Receiver
45 .await
46 .map_err(|_| "EchoAction task cancelled before completion".to_string())
47 }
48}
49
50#[allow(dead_code)]
53fn _Priority(P:EchoPriority) -> EchoPriority { P }