macro_rules! execute {
(
store: [
$($data_type:ty),* $(,)?
],
actors: [
$($actor_type:ty $(: $init_context:expr )? ),* $(,)?
] $(,)?
) => { ... };
}
Expand description
Execute a given set of actors without heap allocation.
use core::convert::Infallible;
use core::fmt::Debug;
use veecle_os_runtime::{Reader, Storable, Writer};
#[derive(Debug, Clone, PartialEq, Eq, Default, Storable)]
pub struct Ping {
value: u32,
}
#[derive(Debug, Clone, PartialEq, Eq, Default, Storable)]
pub struct Pong {
value: u32,
}
#[veecle_os_runtime::actor]
async fn ping_actor(mut ping: Writer<'_, Ping>, pong: Reader<'_, Pong>) -> Infallible {
let mut value = 0;
ping.write(Ping { value }).await;
let mut pong = pong.wait_init().await;
loop {
ping.write(Ping { value }).await;
value += 1;
pong.wait_for_update().await.read(|pong| {
println!("Pong: {}", pong.value);
});
}
}
#[veecle_os_runtime::actor]
async fn pong_actor(mut pong: Writer<'_, Pong>, ping: Reader<'_, Ping>) -> Infallible {
let mut ping = ping.wait_init().await;
loop {
let ping = ping.wait_for_update().await.read_cloned();
println!("Ping: {}", ping.value);
let data = Pong { value: ping.value };
pong.write(data).await;
}
}
futures::executor::block_on(
veecle_os_runtime::execute! {
store: [Ping, Pong],
actors: [PingActor, PongActor],
}
)