momento_functions/macros/
function_spawn.rs1#[macro_export]
26macro_rules! spawn {
27 ($spawn_handler: ident) => {
28 use momento_functions_host::FunctionResult;
29 struct SpawnFunction;
30 momento_functions_wit::function_spawn::export_spawn_function!(SpawnFunction);
31
32 #[automatically_derived]
33 impl momento_functions_wit::function_spawn::exports::momento::functions::guest_function_spawn::Guest for SpawnFunction {
34 fn spawned(payload: Vec<u8>) -> Result<(), momento_functions_wit::function_spawn::momento::functions::types::InvocationError> {
35 $spawn_handler(payload).map_err(Into::into)
36 }
37 }
38 };
39
40 ($post_handler: ident, $request: ident) => {
41 use momento_functions_host::FunctionResult;
42 struct SpawnFunction;
43 momento_functions_wit::function_spawn::export_spawn_function!(SpawnFunction);
44
45 #[automatically_derived]
46 impl momento_functions_wit::function_spawn::exports::momento::functions::guest_function_spawn::Guest for SpawnFunction {
47 fn spawned(payload: Vec<u8>) -> Result<(), momento_functions_wit::function_spawn::momento::functions::types::InvocationError> {
48 let payload: $request = serde_json::from_slice(&payload)
49 .map_err(|e| momento_functions_wit::function_spawn::momento::functions::types::InvocationError::RequestError(format!("could not deserialize json: {e:?}")))?;
50 $post_handler(payload).map_err(Into::into)
51 }
52 }
53 }
54}