Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pub fn new<F, State>(
- system: Arc<ActorSystem>,
- node_id: Uuid,
- name: Option<String>,
- mut state: State,
- mut processor: F,
- ) -> Arc<Actor>
- where
- State: Send + Sync + 'static,
- F: Processor<State> + 'static,
- {
- // FIXME: Issue #33: Let the user pass the size of the channel queue when creating
- // the actor. Create the channel for the actor.
- let (sender, receiver) = secc::create::<Arc<Message>>(32, 10);
- // The sender will be put inside the actor id.
- let aid = ActorId {
- uuid: Uuid::new_v4(),
- node_uuid: node_id,
- name,
- sender: ActorSender::Local(sender),
- is_stopped: AtomicBool::new(false),
- };
- // This handler will manage the state for the actor.
- let handler = Box::new({
- move |aid: ActorId, message: &Arc<Message>| processor(&mut state, aid, message)
- });
- // This is the receiving side of the actor which holds the processor wrapped in the
- // handler type.
- // FIXME Get rid of the need to look up the actor object when enqueuing it for work!
- let actor = Actor {
- aid: Arc::new(aid),
- receiver,
- handler: Mutex::new(handler),
- };
- Arc::new(actor)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement