harmos_runtime/operations/
surface.rs1use std::future::Future;
21use std::sync::Arc;
22
23use super::caller::Identity;
27use super::{CallContext, Context, ContextError, ContextValue, OperationDeclaration, OperationInstance, OperationManager, Response};
28use crate::{Error, Result};
29
30impl harmos_sdk::operations::Host for OperationManager {
45 type Error = Error;
46 type Instance<O: OperationDeclaration> = OperationInstance<O>;
47
48 fn context(&self) -> &CallContext {
49 self.call_context()
50 }
51
52 fn with_value<T: ContextValue>(&self, value: T) -> std::result::Result<Self, ContextError> {
53 let context = self.call_context().with_value(value)?;
54 Ok(self.with_context(context))
55 }
56
57 fn submit<O: OperationDeclaration>(&self, request: O) -> impl Future<Output = Result<OperationInstance<O>>> + Send {
58 std::future::ready(OperationManager::submit(self, request))
59 }
60
61 fn call<O: OperationDeclaration>(&self, request: O) -> impl Future<Output = Result<Response<O::Response>>> + Send {
62 let submitted = OperationManager::submit(self, request);
63 async move { submitted?.await }
64 }
65
66 fn submit_with_resources<O: OperationDeclaration<Response = ()>, R: Send + Sync + 'static>(
67 &self, _: O, resources: Arc<R>,
68 ) -> impl Future<Output = Result<OperationInstance<O>>> + Send {
69 self.activate_resident::<O, R>(O::ID, resources, Identity::Host)
70 }
71}
72
73impl harmos_sdk::operations::Host for Context<'_> {
74 type Error = Error;
75 type Instance<O: OperationDeclaration> = OperationInstance<O>;
76
77 fn context(&self) -> &CallContext {
78 Context::context(self)
79 }
80
81 fn with_value<T: ContextValue>(&self, value: T) -> std::result::Result<Self, ContextError> {
82 let context = Context::context(self).with_value(value)?;
83 let mut child = self.clone();
84 child.operations = child.operations.with_context(context);
85 Ok(child)
86 }
87
88 fn submit<O: OperationDeclaration>(&self, request: O) -> impl Future<Output = Result<OperationInstance<O>>> + Send {
89 std::future::ready(Context::submit(self, request))
90 }
91
92 fn call<O: OperationDeclaration>(&self, request: O) -> impl Future<Output = Result<Response<O::Response>>> + Send {
93 let submitted = Context::submit(self, request);
94 async move { submitted?.await }
95 }
96
97 fn submit_with_resources<O: OperationDeclaration<Response = ()>, R: Send + Sync + 'static>(
100 &self, _: O, resources: Arc<R>,
101 ) -> impl Future<Output = Result<OperationInstance<O>>> + Send {
102 self.operations.activate_resident::<O, R>(O::ID, resources, self.origin.identity.clone())
103 }
104}
105
106