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(-)
@@ -1,10 +1,10 @@
pub mod response;
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;
@@ -35,6 +35,8 @@
impl Actor for Channel {
type Context = Context<Self>;
}
impl Supervised for Channel {}
impl Handler<Broadcast> for Channel {
@@ -1,9 +1,9 @@
#![deny(clippy::nursery, clippy::pedantic)]
#![allow(clippy::module_name_repetitions)]
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 @@
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),
@@ -1,8 +1,11 @@
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};
@@ -31,6 +34,8 @@
pub clients: HashMap<Addr<Client>, InitiatedConnection>,
pub config: Config,
}
impl Supervised for Server {}
impl Handler<UserNickChangeInternal> for Server {
@@ -148,7 +153,7 @@
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,