1use melodium_core::{
2 common::executive::{Output, ResultStatus},
3 *,
4};
5use melodium_macro::mel_model;
6use std::collections::HashMap;
7
8#[mel_model(
12 source ready () () (trigger Block<void>)
13 continuous (continuous)
14)]
15#[derive(Debug)]
16pub struct Engine {
17 model: std::sync::Weak<EngineModel>,
18}
19
20impl Engine {
21 fn new(model: std::sync::Weak<EngineModel>) -> Self {
22 Self { model }
23 }
24
25 async fn continuous(&self) {
26 let model = self.model.upgrade().unwrap();
27
28 model
29 .new_ready(
30 None,
31 &HashMap::new(),
32 Some(Box::new(|mut outputs| {
33 let trigger = outputs.get("trigger");
34
35 vec![Box::new(Box::pin(Self::ready(trigger)))]
36 })),
37 )
38 .await;
39 }
40
41 async fn ready(trigger: Box<dyn Output>) -> ResultStatus {
42 let _ = trigger.send_one(().into()).await;
43 trigger.close().await;
44 ResultStatus::Ok
45 }
46
47 fn invoke_source(&self, _source: &str, _params: HashMap<String, Value>) {}
48}