Skip to main content

datex_core/runtime/execution/context/
remote.rs

1#[cfg(feature = "compiler")]
2use crate::compiler::scope::CompilationScope;
3use crate::{
4    global::dxb_block::OutgoingContextId,
5    runtime::{
6        Runtime,
7        execution::context::{ExecutionContext, ExecutionMode},
8    },
9    values::core_values::endpoint::Endpoint,
10};
11
12#[derive(Debug, Clone)]
13pub struct RemoteExecutionContext {
14    #[cfg(feature = "compiler")]
15    pub compile_scope: CompilationScope,
16    pub endpoint: Endpoint, // FIXME do we need multiple here?
17    pub context_id: Option<OutgoingContextId>,
18    pub execution_mode: ExecutionMode,
19    pub runtime: Runtime,
20}
21
22impl RemoteExecutionContext {
23    /// Creates a new remote execution context with the given endpoint.
24    pub fn new(
25        endpoint: impl Into<Endpoint>,
26        execution_mode: ExecutionMode,
27        runtime: Runtime,
28    ) -> Self {
29        RemoteExecutionContext {
30            #[cfg(feature = "compiler")]
31            compile_scope: CompilationScope::new(execution_mode),
32            endpoint: endpoint.into(),
33            context_id: None,
34            execution_mode,
35            runtime,
36        }
37    }
38}
39
40impl ExecutionContext {
41    pub fn remote(endpoint: impl Into<Endpoint>, runtime: Runtime) -> Self {
42        ExecutionContext::Remote(RemoteExecutionContext::new(
43            endpoint,
44            ExecutionMode::Static,
45            runtime,
46        ))
47    }
48
49    pub fn remote_unbounded(
50        endpoint: impl Into<Endpoint>,
51        runtime: Runtime,
52    ) -> Self {
53        ExecutionContext::Remote(RemoteExecutionContext::new(
54            endpoint,
55            ExecutionMode::unbounded(),
56            runtime,
57        ))
58    }
59}