`giterated_cache` initial implementation
# Giterated Stack - Added the ability for dynamic substack handlers to exist for operations relevant to caching. - Added type metadata to the dynamic types. # Giterated Cache - Created - Implemented caching and fetching from cache. Hell fucking yes!!!! It works so good. Are you snooping in the commit logs because you're curious about the history of giterated? Cool that it got so big... tell me I say hi :)
parent: tbd commit: 86afeef
1 | use ; |
2 | |
3 | use FutureExt; |
4 | use |
5 | , | OperationError
6 | , | Instance
7 | , |
8 | , | GiteratedOperation
9 | , | Setting
10 | , | GiteratedObjectValue
11 | ; |
12 | use ; |
13 | |
14 | use crate:: |
15 | , MetadataProvider, AnyFailure, AnyObject, AnyOperation, | HandlerWrapper
16 | AnySetting, AnySuccess, AnyValue, GiteratedStack, GiteratedStackState, IntoGiteratedHandler, |
17 | MaybeDynamicObject, MaybeDynamicValue, ObjectOperationPair, ObjectSettingPair, ObjectValuePair, |
18 | OperationHandler, RuntimeMetadata, SettingChange, SettingGetter, StackOperationState, |
19 | ValueChange, ValueGetter, |
20 | ; |
21 | |
22 | |
23 | pub(crate) operation_handlers: , |
24 | pub(crate) value_getters: , |
25 | pub(crate) setting_getters: , |
26 | pub(crate) metadata: RuntimeMetadata, |
27 | pub(crate) value_change: , |
28 | pub(crate) metadata_providers: , |
29 | pub(crate) setting_change: , |
30 | |
31 | pub(crate) state: S, |
32 | |
33 | |
34 | |
35 | |
36 | Self |
37 | operation_handlers: Default default, |
38 | value_getters: Default default, |
39 | setting_getters: Default default, |
40 | metadata: Default default, |
41 | value_change: Default default, |
42 | metadata_providers: Default default, |
43 | setting_change: Default default, |
44 | state, |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | /// Insert an operation handler into the runtime builder. |
51 | /// |
52 | /// # Type Registration |
53 | /// Inserting the handler will automatically, if required, register the operation type of the |
54 | /// handler. It will **not** register the object type automatically. |
55 | |
56 | |
57 | O: GiteratedObject + Clone, |
58 | D: + Clone, |
59 | H: |
60 | (O, D), |
61 | A, |
62 | S, |
63 | StackOperationState, |
64 | , |
65 | > + Send |
66 | + Sync |
67 | + 'static, |
68 | O: 'static, |
69 | D: 'static, |
70 | : Debug + 'static, | Failure
71 | : 'static, | Success
72 | |
73 | let wrapped = new; |
74 | |
75 | let wrapped = wrapped.map |
76 | |
77 | |
78 | Ok |
79 | any_object.unwrap .clone, | .
80 | any_operation.unwrap .clone, | .
81 | |
82 | , |
83 | ; |
84 | |
85 | let wrapped = wrapped.map_return |
86 | Ok => Ok, |
87 | Err => Err |
88 | => | Operation
89 | Operation |
90 | |
91 | => Internal, | Internal
92 | => Unhandled, | Unhandled
93 | , |
94 | ; |
95 | |
96 | let pair = ; |
97 | |
98 | self.operation_handlers.insert; |
99 | |
100 | self.metadata.; |
101 | |
102 | self |
103 | |
104 | |
105 | /// Register a [`GiteratedObject`] type with the runtime. |
106 | /// |
107 | /// # Type Registration |
108 | /// This will register the provided object type. |
109 | |
110 | self.metadata.; |
111 | |
112 | // Insert handler so ObjectRequest is handled properly |
113 | |
114 | self.operation |
115 | move |_object: Instance, |
116 | operation: ObjectRequest, |
117 | _state: S, |
118 | _operation_state: StackOperationState, |
119 | stack: | |
120 | let operation = operation.clone; |
121 | async move |
122 | for in stack.metadata.objects.iter |
123 | if .is_ok |
124 | return Ok; |
125 | |
126 | |
127 | |
128 | Err |
129 | |
130 | .boxed_local |
131 | , |
132 | ; |
133 | |
134 | self |
135 | |
136 | |
137 | /// Register a [`Setting`] type with the runtime. |
138 | /// |
139 | /// # Type Registration |
140 | /// This will register the provided setting type. |
141 | |
142 | &mut self, |
143 | |
144 | self.metadata.; |
145 | |
146 | self |
147 | |
148 | |
149 | /// Register a [`GiteratedObjectValue`] that is also a [`Setting`], which |
150 | /// allows for automatic value updates. |
151 | |
152 | O: GiteratedObject + 'static + Clone, |
153 | T: + Setting + 'static + Clone, |
154 | > |
155 | &mut self, |
156 | |
157 | self.metadata.; |
158 | self.metadata.; |
159 | |
160 | self.setting_change.insert |
161 | , |
162 | new |
163 | , |
164 | move |object: AnyObject, |
165 | setting: AnySetting, |
166 | _state: , |
167 | operation_state: StackOperationState, |
168 | stack: | |
169 | trace! |
170 | "value setting updated {}::{}", |
171 | , | object_name
172 | value_name |
173 | ; |
174 | let object = object.clone; |
175 | async move |
176 | let object = object. .unwrap; |
177 | let setting = setting. .unwrap; |
178 | stack |
179 | .value_update |
180 | .await; |
181 | Ok |
182 | |
183 | .boxed_local |
184 | , |
185 | , |
186 | ; |
187 | |
188 | let wrapped = new |
189 | self.state.clone, |
190 | |
191 | |
192 | _state: _, |
193 | _operation_state: StackOperationState, |
194 | stack: | |
195 | info!; |
196 | let object = object.clone; |
197 | async move |
198 | match stack |
199 | . |
200 | .await |
201 | |
202 | Ok => Ok, |
203 | Err => |
204 | panic!; |
205 | |
206 | |
207 | |
208 | .boxed_local |
209 | , |
210 | ; |
211 | |
212 | self.value_getters |
213 | .insert; |
214 | |
215 | self |
216 | |
217 | |
218 | /// Register a [`GiteratedObjectValue<O>`] type with the runtime, providing |
219 | /// its associated handler for [`GetValue`]. |
220 | /// |
221 | /// # Type Registration |
222 | /// This will register the provided [`GiteratedObjectValue`] type for its matching / specified |
223 | /// object type. It will **not** register the object type automatically. |
224 | |
225 | |
226 | O: MaybeDynamicObject + 'static, |
227 | F: |
228 | (O, String), |
229 | A, |
230 | S, |
231 | StackOperationState, |
232 | , |
233 | > + Send |
234 | + Sync, |
235 | F: 'static, |
236 | |
237 | let wrapped = new; |
238 | |
239 | let wrapped = wrapped.map |
240 | |
241 | Ok |
242 | , |
243 | ; |
244 | |
245 | let wrapped = wrapped.map_return |
246 | Ok => Ok, |
247 | Err => Err |
248 | => Internal, | Operation
249 | => Internal, | Internal
250 | => Unhandled, | Unhandled
251 | , |
252 | ; |
253 | |
254 | assert! |
255 | .value_getters |
256 | .insert |
257 | ObjectValuePair |
258 | object_kind: object_name, |
259 | value_kind: "any" |
260 | , |
261 | wrapped |
262 | |
263 | .is_none; |
264 | |
265 | self |
266 | |
267 | |
268 | |
269 | |
270 | F: |
271 | (O, V), |
272 | A, |
273 | S, |
274 | StackOperationState, |
275 | , |
276 | > + Send |
277 | + Sync, |
278 | V: MaybeDynamicValue + Clone + 'static, |
279 | O: 'static + MaybeDynamicObject, |
280 | V: 'static, |
281 | F: 'static, |
282 | |
283 | let wrapped = new; |
284 | |
285 | let wrapped = wrapped.map |
286 | |
287 | Ok |
288 | , |
289 | ; |
290 | |
291 | assert! |
292 | .value_change |
293 | .insert |
294 | ObjectValuePair |
295 | object_kind: object_name, |
296 | value_kind: value_name |
297 | , |
298 | wrapped |
299 | |
300 | .is_none; |
301 | |
302 | self |
303 | |
304 | |
305 | |
306 | self.metadata_providers.push; |
307 | |
308 | self |
309 | |
310 | |
311 | |
312 | |
313 | |
314 | ; |
315 |