January 2019
Intermediate to advanced
520 pages
14h 32m
English
Before we implement a handler of HTTP requests, let's add a function that uses State to send a message to CountActor and use the returned value to print it with LogActor. Look at the following function:
fn count_up(state: &State, path: &str) -> impl Future<Item=(), Error=Error> { let path = path.to_string(); let log = state.log.clone(); state.count.send(Count(path.clone())) .and_then(move |value| { let message = format!("total requests for '{}' is {}", path, value); log.send(Log(message)) }) .map_err(|err| other(err.compat()))}
We converted the path into a String, because we need this type for the Count message, and to move it to a Future that sends a Log message to LogActor. Also, we have to clone Addr to LogActor, because ...
Read now
Unlock full access