myriam-rs
Local and remote actor model implementation with an API heavily inspired (but not necessarily equivalent) in Goblins.
use std::time::Duration;
use serde::{Deserialize, Serialize};
use myriam::{
actors::{
Actor,
remote::{
self,
dencoder::bincode::BincodeDencoder,
netlayer::tcp_layer::TcpNetLayer,
router::{RemoteHandle, Router, RouterOpts},
},
},
messaging::{Message, Reply},
};
struct Mult {
pub a: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize, thiserror::Error)]
#[error("uh oh")]
struct SomeError;
impl Actor<u32, u32, SomeError> for Mult {
async fn handler(&self, input: u32) -> Result<u32, SomeError> {
Ok(input * self.a)
}
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let (local_handle, untyped_handle)
= remote::spawn_untyped::<_, _, _, BincodeDencoder>(Mult { a: 3 }).await?;
let router_handle = Router::with_netlayer(TcpNetLayer::new(), Some(RouterOpts::default())).await?;
let address = router_handle.attach(untyped_handle).await?;
let remote_handle
= RemoteHandle::<u32, u32, SomeError, BincodeDencoder, TcpNetLayer>::new(&address, TcpNetLayer::new());
let res = remote_handle.send(Message::Task(42)).await?;
router_handle.revoke(&address).await?;
tokio::time::sleep(Duration::from_millis(100));
remote_handle.send(Message::Ping).await.unwrap_err();
Ok(())
}
features
remote (default): support for remote messaging
tcp (default): TCP test-only net layer
tor (default): Tor net layer - requires a running and properly configured Tor router
license
Copyright 2024 Ariela Wenner
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.