SHARE
TWEET

Untitled

a guest Aug 20th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. pub fn new<F, State>(
  2.         system: Arc<ActorSystem>,
  3.         node_id: Uuid,
  4.         name: Option<String>,
  5.         mut state: State,
  6.         mut processor: F,
  7.     ) -> Arc<Actor>
  8.     where
  9.         State: Send + Sync + 'static,
  10.         F: Processor<State> + 'static,
  11.     {
  12.         // FIXME: Issue #33: Let the user pass the size of the channel queue when creating
  13.         // the actor.  Create the channel for the actor.
  14.         let (sender, receiver) = secc::create::<Arc<Message>>(32, 10);
  15.  
  16.         // The sender will be put inside the actor id.
  17.         let aid = ActorId {
  18.             uuid: Uuid::new_v4(),
  19.             node_uuid: node_id,
  20.             name,
  21.             sender: ActorSender::Local(sender),
  22.             is_stopped: AtomicBool::new(false),
  23.         };
  24.  
  25.         // This handler will manage the state for the actor.
  26.         let handler = Box::new({
  27.             move |aid: ActorId, message: &Arc<Message>| processor(&mut state, aid, message)
  28.         });
  29.  
  30.         // This is the receiving side of the actor which holds the processor wrapped in the
  31.         // handler type.
  32.         // FIXME Get rid of the need to look up the actor object when enqueuing it for work!
  33.         let actor = Actor {
  34.             aid: Arc::new(aid),
  35.             receiver,
  36.             handler: Mutex::new(handler),
  37.         };
  38.  
  39.         Arc::new(actor)
  40.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top