January 2019
Intermediate to advanced
520 pages
14h 32m
English
To consume responses from a worker, our server has to start QueueActor with a handler that will update the shared state of a server. Create a ServerHandler struct that keeps a copy of the SharedTasks reference:
struct ServerHandler { tasks: SharedTasks,}
Implement the QueueHandler for this struct:
impl QueueHandler for ServerHandler { type Incoming = QrResponse; type Outgoing = QrRequest; fn incoming(&self) -> &str { RESPONSES } fn outgoing(&self) -> &str { REQUESTS } fn handle( &self, id: &TaskId, incoming: Self::Incoming, ) -> Result<Option<Self::Outgoing>, Error> { self.tasks.lock().unwrap().get_mut(id).map(move |rec| { rec.status = Status::Done(incoming); }); Ok(None) }}
The handler of the server has to use the RESPONSES ...
Read now
Unlock full access