Soft question: micro components within a process

This all happens within a single process.

Is there a style of programming where we try to design a Rust process like the internet. I.e. we define

pub enum A_Msg {};
pub enum B_Msg {};
pub enum C_Msg {};
pub enum D_Msg {};
pub enum E_Msg {};

pub enum   All_msg {
  A(A_Msg),
  B(B_Msg),
  C(C_msg),
  D(D_msg),
  E(E_msg)
}

then we have a global queue

Rc<RefCell<Deque<All_Msg>>>

and we register components for handling A_Msg, B_Msg, C_Msg, D_Msg, E_Msg, and the global handler dispatches msgs to components.

Is this a common pattern in Rust ? If so, what is the name and where can I read up more on this.

Broadly (and not specifically to Rust), you could call that an event loop; the queue is an event queue.

If instead each component has its own queue, and the component's state is solely owned by the loop that processes the messages, then the components are actors. This allows more parallelism since each actor can work independently, but in that case there is no longer a definite ordering of all messages in the entire system.

3 Likes

LOL. Good point. It is basically an EventLoop where the handler is a match statement dispatching to one of 5 handlers.