Start Server and Channels in a supervisor
Diff
src/channel.rs | 4 +++-
src/main.rs | 4 ++--
src/server.rs | 9 +++++++--
3 files changed, 12 insertions(+), 5 deletions(-)
@@ -4,7 +4,7 @@ use std::collections::HashMap;
use actix::{
Actor, ActorFutureExt, Addr, AsyncContext, Context, Handler, MessageResult, ResponseActFuture,
WrapFuture,
Supervised, WrapFuture,
};
use chrono::{DateTime, Utc};
use futures::future::Either;
@@ -36,6 +36,8 @@ impl Actor for Channel {
type Context = Context<Self>;
}
impl Supervised for Channel {}
impl Handler<Broadcast> for Channel {
type Result = ();
@@ -3,7 +3,7 @@
use std::{collections::HashMap, sync::Arc};
use actix::{io::FramedWrite, Actor, Addr, AsyncContext};
use actix::{io::FramedWrite, Actor, Addr, AsyncContext, Supervisor};
use actix_rt::{Arbiter, System};
use clap::Parser;
use irc_proto::IrcCodec;
@@ -48,7 +48,7 @@ async fn main() -> anyhow::Result<()> {
let listen_address = opts.config.listen_address;
let client_threads = opts.config.client_threads;
let server = Server::start_in_arbiter(&Arbiter::new().handle(), |_ctx| Server {
let server = Supervisor::start_in_arbiter(&Arbiter::new().handle(), |_ctx| Server {
channels: HashMap::default(),
clients: HashMap::default(),
channel_arbiters: build_arbiters(opts.config.channel_threads),
@@ -2,7 +2,10 @@ pub mod response;
use std::collections::HashMap;
use actix::{Actor, Addr, AsyncContext, Context, Handler, MessageResult, ResponseFuture};
use actix::{
Actor, Addr, AsyncContext, Context, Handler, MessageResult, ResponseFuture, Supervised,
Supervisor,
};
use actix_rt::Arbiter;
use futures::{stream::FuturesOrdered, TryFutureExt};
use irc_proto::{Command, Message, Prefix, Response};
@@ -32,6 +35,8 @@ pub struct Server {
pub config: Config,
}
impl Supervised for Server {}
impl Handler<UserNickChangeInternal> for Server {
type Result = ();
@@ -148,7 +153,7 @@ impl Handler<ChannelJoin> for Server {
let channel_name = msg.channel_name.clone();
let server = ctx.address();
Channel::start_in_arbiter(&arbiter, move |_ctx| Channel {
Supervisor::start_in_arbiter(&arbiter, move |_ctx| Channel {
name: channel_name,
clients: HashMap::new(),
topic: None,