January 2019
Intermediate to advanced
520 pages
14h 32m
English
We need our own type that will implement the Ring trait to implement RPC interface of a service. But we also have to keep a Sender for a worker to send actions to it. Add the RingImpl struct with a Sender of Action wrapped with Mutex, because the Ring trait requires the Sync trait implementation as well:
struct RingImpl { sender: Mutex<Sender<Action>>,}
We will construct an instance from the Sender instance:
impl RingImpl { fn new(sender: Sender<Action>) -> Self { Self { sender: Mutex::new(sender), } }}
For every incoming method call, we need to send Action to a worker and we can add a method to the RingImpl implementation to reuse it in all handlers:
fn send_action(&self, action: Action) -> SingleResponse<Empty> { ...Read now
Unlock full access