You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried to build a simple actor with a single message type, but apparently the first message I receive is not spawned by my code. Are there other "internal" messages being passed to handle?
If so, could documentation be fixed on examples that represent unknown case as a panic?
If not, is axiom haunted? :-)
Sample code which shouldn't panic:
#[macro_use]
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate tokio;
use axiom::prelude::*;
#[tokio::main]
async fn main() {
env_logger::Builder::from_env("AXIOM_LOG")
.filter_level(log::LevelFilter::Debug)
.init();
let actor_config = ActorSystemConfig::default();
let actor_system = ActorSystem::create(actor_config);
let worker = actor_system
.spawn()
.name("Worker")
.with(Worker, Worker::handle)
.expect("a worker");
worker
.send_new(WorkerMessage(0))
.expect("message should pass");
}
#[derive(Serialize, Deserialize)]
pub struct WorkerMessage(u8);
pub struct Worker;
impl Worker {
async fn handle(self, _context: Context, message: Message) -> ActorResult<Self> {
let value = message
.content_as::<WorkerMessage>()
.expect("only message should be WorkerMessage");
assert!(value.0 != 0);
Ok(Status::done(self))
}
}
The text was updated successfully, but these errors were encountered:
Aha, okay. I'd like to suggest to fix second example in "Getting Started" section of main documentation page, because panic!("Failed to dispatch properly"); line would always trigger.
Thanks for the issue. Do you have a PR on the doc fix?
I am back in the project now after other priorities have been handled, and I am going to start cleaning up things. As for the system messages, the very first message is an init and that is used to allow the user to set up things before the actor starts processing.
I tried to build a simple actor with a single message type, but apparently the first message I receive is not spawned by my code. Are there other "internal" messages being passed to handle?
If so, could documentation be fixed on examples that represent unknown case as a panic?
If not, is axiom haunted? :-)
Sample code which shouldn't panic:
The text was updated successfully, but these errors were encountered: