January 2019
Intermediate to advanced
520 pages
14h 32m
English
Since we will be extended the example from the previous section, we reuse the State struct, but add an Addr to the Repeater actor that we will create later in the main function:
pub struct State { counter: RefCell<i64>, cache: CacheLink, repeater: Addr<RepeaterActor>, }
Update the constructor to fill the repeater field:
fn new(cache: CacheLink, repeater: Addr<RepeaterActor>) -> Self { Self { counter: RefCell::default(), cache, repeater, } }
Now, we can spawn a RepeaterActor, set the address of the actor to State, and use it as the state for our App:
let repeater = RepeaterActor::new().start(); server::new(move || { let state = State::new(cache.clone(), repeater.clone()); App::with_state(state) .resource("/ws", ...Read now
Unlock full access