January 2019
Intermediate to advanced
520 pages
14h 32m
English
We have already created functions that create app instances of actix in Chapter 11, Involving Concurrency with Actors and Actix Crate. Return to that chapter if you don't remember how to attach handlers and a state to an application, and look at the main function, as follows:
fn main() -> Result<(), Error> { env_logger::init(); let mut sys = System::new("rabbit-actix-server"); let tasks = Arc::new(Mutex::new(IndexMap::new())); let addr = QueueActor::new( ServerHandler { tasks: tasks.clone(), }, &mut sys, )?; let state = State { tasks: tasks.clone(), addr, }; server::new(move || { App::with_state(state.clone()) .middleware(middleware::Logger::default()) .resource("/", |r| r.f(index_handler)) .resource("/task", |r| { r.method(http::Method::POST).with_async(upload_handler); ...Read now
Unlock full access