Skip to content

Commit

Permalink
refactor: Modify actor receive function parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
j5ik2o committed Jul 14, 2024
1 parent 7640231 commit 580583f
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 15 deletions.
5 changes: 3 additions & 2 deletions examples/actor-hello-world/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use nexus_acto_rs::actor::actor::actor_error::ActorError;
use nexus_acto_rs::actor::actor::props::Props;
use nexus_acto_rs::actor::actor_system::ActorSystem;
use nexus_acto_rs::actor::context::context_handle::ContextHandle;
use nexus_acto_rs::actor::context::{SenderPart, SpawnerPart};
use nexus_acto_rs::actor::context::{MessagePart, SenderPart, SpawnerPart};
use nexus_acto_rs::actor::message::message::Message;
use nexus_acto_rs::actor::message::message_handle::MessageHandle;
use std::any::Any;
Expand All @@ -31,7 +31,8 @@ struct HelloActor;

#[async_trait]
impl Actor for HelloActor {
async fn receive(&mut self, _: ContextHandle, message_handle: MessageHandle) -> Result<(), ActorError> {
async fn receive(&mut self, ctx: ContextHandle) -> Result<(), ActorError> {
let message_handle = ctx.get_message_handle().await;
let hello = message_handle.to_typed::<Hello>().unwrap();
println!("Hello, {}!", hello.who);
Ok(())
Expand Down
7 changes: 2 additions & 5 deletions examples/actor-supervision/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@ impl Parent {

#[async_trait]
impl Actor for Parent {
async fn receive(
&mut self,
mut context_handle: ContextHandle,
message_handle: MessageHandle,
) -> Result<(), ActorError> {
async fn receive(&mut self, mut context_handle: ContextHandle) -> Result<(), ActorError> {
let message_handle = context_handle.get_message_handle().await;
let msg = message_handle.to_typed::<Hello>().unwrap();
let props = Props::from_actor_producer(|_| async { Child::new() }).await;
let child = context_handle.spawn(props).await;
Expand Down
3 changes: 0 additions & 3 deletions src/actor/actor/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ use std::fmt::Debug;
use async_trait::async_trait;

use crate::actor::actor::actor_error::ActorError;
use crate::actor::actor::actor_inner_error::ActorInnerError;
use crate::actor::context::context_handle::ContextHandle;
use crate::actor::context::MessagePart;
use crate::actor::message::auto_receive_message::AutoReceiveMessage;
use crate::actor::message::message_handle::MessageHandle;
use crate::actor::message::message_or_envelope::{unwrap_envelope_message, MessageEnvelope};
use crate::actor::message::terminate_info::TerminateInfo;
use crate::actor::supervisor::supervisor_strategy_handle::SupervisorStrategyHandle;

Expand Down
1 change: 0 additions & 1 deletion src/actor/actor/actor_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use tokio::sync::Mutex;
use crate::actor::actor::actor::Actor;
use crate::actor::actor::actor_error::ActorError;
use crate::actor::context::context_handle::ContextHandle;
use crate::actor::message::message_handle::MessageHandle;
use crate::actor::supervisor::supervisor_strategy_handle::SupervisorStrategyHandle;

#[derive(Debug, Clone)]
Expand Down
5 changes: 2 additions & 3 deletions src/actor/actor/behavior_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ mod tests {
use crate::actor::actor::actor::Actor;
use crate::actor::actor::actor_error::ActorError;
use crate::actor::actor::behavior::Behavior;
use crate::actor::actor::props::Props;
use crate::actor::actor_system::ActorSystem;

use crate::actor::context::context_handle::ContextHandle;
use crate::actor::context::{BasePart, MessagePart, SenderPart, SpawnerPart};
use crate::actor::context::{BasePart, MessagePart};
use crate::actor::message::message::Message;
use crate::actor::message::response::ResponseHandle;
use async_trait::async_trait;
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ impl Actor for ChildActor {
Ok(())
}

async fn receive(&mut self, _: ContextHandle, message_handle: MessageHandle) -> Result<(), ActorError> {
async fn receive(&mut self, ctx: ContextHandle) -> Result<(), ActorError> {
let message_handle = ctx.get_message_handle().await;
tracing::debug!("ChildActor::receive: msg = {:?}", message_handle);
Ok(())
}
Expand Down

0 comments on commit 580583f

Please sign in to comment.