1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
pub use context::*;
#[cido_macros::_impls]
mod context {
use crate::prelude::*;
/// Allows synchronizing code within the preprocessing context so that event ordering can be maintained
pub struct PreprocessingQueueRegister<'a, C: Cidomap> {
inner: std::marker::PhantomData<&'a C>,
}
impl<'a, C: Cidomap> PreprocessingQueueRegister<'a, C> {
/// Wait for the order in line that this was created in
pub async fn wait(&mut self) -> usize {
unimplemented!()
}
/// Mark all synchronization needs finished and let the next one execute
pub fn finish(self) {}
}
impl<'a, C: Cidomap> Drop for PreprocessingQueueRegister<'a, C> {
fn drop(&mut self) {}
}
/// Allows making network calls before entering the generator or handler functions
///
/// The generator and handler functions are all executed sequentially so any waiting done for network
/// calls is expensive. This struct is used in the preprocessor functions which are all executed
/// simulatenously so that all waiting can happen concurrently
///
/// This struct is passed to the preprocessor handler
#[allow(clippy::module_name_repetitions)]
pub struct PreprocessingContext<C: Cidomap> {
inner: std::marker::PhantomData<std::sync::Arc<C::Network>>,
}
impl<C: Cidomap> PreprocessingContext<C> {
/// Get access to the network for making calls
pub fn network(&self) -> &<C as Cidomap>::Network {
unimplemented!()
}
/// Registers with a queue that guarantees single order processing. This is useful
/// when some order needs to be enforced to avoid race conditions that can otherwise
/// arise from running all futures concurrently.
///
/// Must be called in synchronous code before the async future is created. This is because the
/// order that this function is called matters and creating the futures happens separately from
/// polling them.
///
/// ```rust,ignore
/// async fn preprocess_event(cx: &Preprocessor<Cidomap>) -> impl Future<Output = Result<(), Cidomap::Error> {
/// let wait = cs.register_serial_queue();
/// async move {
/// let _place_in_line = wait.wait().await;
/// // do some processing
/// wait.finish();
/// // finish processing
/// }
/// }
/// ```
///
/// All futures that register can await the returned value to get their place in line
/// when the register has `finish` called then the next one in line will be signaled and allowed
/// to execute.
pub fn register_serial_queue(&self) -> PreprocessingQueueRegister<'_, C> {
unimplemented!()
}
}
impl<C: Cidomap> Clone for PreprocessingContext<C> {
fn clone(&self) -> Self {
unimplemented!()
}
}
/// Allows making new filter sources
///
/// This struct is passed to the generator handler
#[allow(clippy::module_name_repetitions)]
pub struct GeneratorContext<'a, C: Cidomap> {
inner: std::marker::PhantomData<&'a mut std::cell::RefCell<C>>,
}
impl<'a, C: Cidomap> GeneratorContext<'a, C> {
/// Gives a reference to the network if any calls need to be made
///
/// If possible this should only be used in preprocessing and the results can be
/// cached and forwarded to the event handler so that no time is spent waiting
pub fn network(&self) -> &<C as Cidomap>::Network {
unimplemented!()
}
/// Create a new source
pub async fn create_source<F: ProcessingOrderFilter<Network = <C as Cidomap>::Network>>(
&mut self,
p: F::Param,
) -> Result<(), CidomapError> {
let _ = p;
Ok(())
}
}
/// Allows interacting with the database to load and save entities and events
///
/// This struct is passed to the final handler
pub struct Context<'a, C: Cidomap> {
inner: std::marker::PhantomData<&'a mut std::cell::RefCell<C>>,
}
impl<'a, C: Cidomap> Context<'a, C> {
/// Load a mutable entity or event and return None if it doesn't exist.
///
/// If you will be creating an entity or event if it doesn't exist, use `load_mut_or_else` as it
/// is more ergonomic and requires only a single cache lookup
///
/// This function can be unwrapped because any errors returned are not recoverable by handler code
pub async fn load_mut<E>(
&self,
id: impl CacheKey<E>,
) -> Result<Option<RefMut<'_, E>>, CidomapError>
where
E: Transformer<Cidomap = C>,
{
let _ = id;
unimplemented!()
}
/// Load an immutable entity or event and return None if it doesn't exist.
///
/// This function can be unwrapped because any errors returned are not recoverable by handler code
pub async fn load<E>(&'a self, id: impl CacheKey<E>) -> Result<Option<Ref<'a, E>>, CidomapError>
where
E: Transformer<Cidomap = C>,
{
let _ = id;
unimplemented!()
}
/// Load a mutable entity or event or else execute an `AsyncFnOnce(id: Id)` if it doesn't exist
///
/// This function can be unwrapped because any errors returned are not recoverable by handler code
pub async fn load_mut_or_else<E>(
&'a self,
id: impl CacheKey<E>,
f: impl AsyncFnOnce(<E as Identifiable>::Id) -> Result<E, C::Error>,
) -> Result<RefMut<'a, E>, CidomapError>
where
E: Transformer<Cidomap = C>,
{
let _ = id;
let _ = f;
unimplemented!()
}
/// Saves a new entity.
///
/// # Errors
/// This function will return an error if the entity being saved is already cached.
pub async fn save<E>(&self, entity: E) -> Result<(), CidomapError>
where
E: Transformer<Cidomap = C>,
{
let _ = entity;
Ok(())
}
/// Query all instances of a type
///
/// This is generally used in the `create` function on the Cidomap trait
///
/// This function can be unwrapped because any errors returned are not recoverable by handler code
pub async fn dynamic_query<D>(&self, d: &mut D) -> Result<(), CidomapError>
where
D: Query<Cidomap = C>,
{
let _ = d;
Ok(())
}
/// Returns a references to the network so that calls can be made if necessary
///
/// If possible this should only be used in preprocessing and the results can be
/// cached and forwarded to the event handler so that no time is spent waiting
pub fn network(&self) -> &<C as Cidomap>::Network {
unimplemented!()
}
}
}