January 2019
Intermediate to advanced
520 pages
14h 32m
English
We will add an actor to resend messages to other actors. We need some basic types from the actix crate, along with a HashSet to keep addresses of actors. Import the NewComment struct, which we will clone and resend:
use actix::{Actor, Context, Handler, Message, Recipient};use std::collections::HashSet;use super::NewComment;
Add a RepeaterActor struct with a listeners field of the HashSet type that contains Recipient instances:
pub struct RepeaterActor { listeners: HashSet<Recipient<RepeaterUpdate>>,}
You are familiar with the Addr type, but we haven't used Recipient before. Actually, you can convert any Addr instance into a Recipient using the recipient method call. The Recipient type is an address that supports only one type of
Read now
Unlock full access