diff --git a/crates/oxidize-chat/src/chat.rs b/crates/oxidize-chat/src/chat.rs index ae9ef51c..119e8c67 100644 --- a/crates/oxidize-chat/src/chat.rs +++ b/crates/oxidize-chat/src/chat.rs @@ -251,7 +251,7 @@ impl ChatLoop<'_> { None }; - let mut hook_futures = common::Futures::new(); + let mut hook_futures = Vec::new(); for module in modules { tracing::trace!("Initializing module: {}", module.ty()); @@ -320,6 +320,10 @@ impl ChatLoop<'_> { messages_future } + for future in &mut hook_futures { + futures.push(future.as_mut()); + } + // We maintain separate collections of local futures which we add // potentially user-defined tasks to, to allow them to .await // concurrently with the main chat task. @@ -400,19 +404,6 @@ impl ChatLoop<'_> { } } } - Some(future) = hook_futures.next() => { - match future { - Ok(..) => { - tracing::warn!("Chat component exited, exiting..."); - return Ok(()); - } - Err(e) => { - common::log_warn!(e, "Chat component errored, restarting in 5 seconds"); - tokio::time::sleep(time::Duration::from_secs(5)).await; - return Ok(()); - } - } - } Some(future) = futures.next() => { match future { Ok(..) => { @@ -449,7 +440,7 @@ impl ChatLoop<'_> { handler.send_ping()?; } _ = &mut *handler.pong_timeout => { - bail!("server not responding"); + bail!("Server not responding"); } update = whitelisted_hosts_stream.recv() => { handler.whitelisted_hosts = update; @@ -483,7 +474,7 @@ impl ChatLoop<'_> { } } _ = &mut outgoing => { - bail!("outgoing future ended unexpectedly"); + bail!("Outgoing future ended unexpectedly"); } _ = &mut leave => { break; diff --git a/crates/oxidize-chat/src/module.rs b/crates/oxidize-chat/src/module.rs index 2b7de952..07069fb9 100644 --- a/crates/oxidize-chat/src/module.rs +++ b/crates/oxidize-chat/src/module.rs @@ -1,5 +1,6 @@ use async_injector::Injector; use async_trait::async_trait; +use common::BoxFuture; use std::collections::HashMap; use std::sync::Arc; @@ -38,7 +39,7 @@ pub struct HookContext<'a, 'task> { pub sender: &'a sender::Sender, pub settings: &'a settings::Settings<::auth::Scope>, pub handlers: &'a mut Handlers, - pub tasks: &'a mut common::Futures<'task, Result<()>>, + pub tasks: &'a mut Vec>>, } /// Trait used to hook up a module. diff --git a/crates/oxidize-common/src/futures.rs b/crates/oxidize-common/src/futures.rs index 82d67777..bd4e77c5 100644 --- a/crates/oxidize-common/src/futures.rs +++ b/crates/oxidize-common/src/futures.rs @@ -7,11 +7,6 @@ use crate::BoxFuture; /// Collection of boxed futures to drive. pub type Futures<'a, O> = ::futures_util::stream::FuturesUnordered>; -/// Collection of local futures to drive. -pub type LocalFutures<'a, O> = ::futures_util::stream::FuturesUnordered< - std::pin::Pin + 'a>>, ->; - /// Run a collection of borrowed futures. pub struct BorrowedFutures<'a, O> { inner: ::futures_util::stream::FuturesUnordered>>, @@ -19,10 +14,7 @@ pub struct BorrowedFutures<'a, O> { impl<'a, O> BorrowedFutures<'a, O> { /// Push a borrowed future into the local collection. - pub fn push(&mut self, future: Pin<&'a mut F>) - where - F: Future, - { + pub fn push(&mut self, future: Pin<&'a mut dyn Future>) { self.inner.push(future); } diff --git a/crates/oxidize-common/src/lib.rs b/crates/oxidize-common/src/lib.rs index b5f0c512..a83dc2af 100644 --- a/crates/oxidize-common/src/lib.rs +++ b/crates/oxidize-common/src/lib.rs @@ -38,7 +38,7 @@ pub use self::percentage::percentage; #[macro_use] mod futures; -pub use self::futures::{BorrowedFutures, Futures, LocalFutures}; +pub use self::futures::{BorrowedFutures, Futures}; /// A boxed future. pub type BoxFuture<'a, T> = std::pin::Pin + Send + 'a>>;