Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown messages #137

Open
giacomocariello opened this issue Mar 3, 2020 · 3 comments
Open

Unknown messages #137

giacomocariello opened this issue Mar 3, 2020 · 3 comments

Comments

@giacomocariello
Copy link

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))
    }
}
@go2bodhi
Copy link

go2bodhi commented Mar 4, 2020

Look at axiom::system::SystemMsg

@giacomocariello
Copy link
Author

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.

@rsimmonsjr
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants