diff --git a/CHANGELOG.md b/CHANGELOG.md index 5724d59..e8118d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ Procedure when bumping the version number: - `bot::command::ClapCommand::execute` now returns a `Result` instead of a `Result<(), E>` - `bot::command::Command::execute` now returns a `Result` instead of a `Result<(), E>` - `bot::commands::Commands::handle_packet` now returns a `Result` instead of a `Result<(), E>` +- `bot::instance::Instance` now implements `Clone` ### Fixed - `phone` and `mobile` emoji diff --git a/src/bot/instance.rs b/src/bot/instance.rs index 04ce031..83a1117 100644 --- a/src/bot/instance.rs +++ b/src/bot/instance.rs @@ -273,13 +273,13 @@ enum RunError { /// either case, the last event the instance sends will be an /// [`Event::Stopped`]. If it is not stopped using one of these two ways, it /// will continue to run and reconnect indefinitely. -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct Instance { config: InstanceConfig, request_tx: mpsc::UnboundedSender, // In theory, request_tx should be sufficient as canary, but I'm not sure // exactly how to check it during the reconnect timeout. - _canary_tx: oneshot::Sender, + _canary_tx: mpsc::UnboundedSender, } impl Instance { @@ -312,7 +312,7 @@ impl Instance { idebug!(config, "Created with config {config:?}"); let (request_tx, request_rx) = mpsc::unbounded_channel(); - let (canary_tx, canary_rx) = oneshot::channel(); + let (canary_tx, canary_rx) = mpsc::unbounded_channel(); tokio::spawn(Self::run::( config.clone(), @@ -360,11 +360,11 @@ impl Instance { config: InstanceConfig, on_event: F, request_rx: mpsc::UnboundedReceiver, - canary_rx: oneshot::Receiver, + mut canary_rx: mpsc::UnboundedReceiver, ) { select! { _ = Self::stay_connected(&config, &on_event, request_rx) => (), - _ = canary_rx => { idebug!(config, "Instance dropped"); }, + _ = canary_rx.recv() => { idebug!(config, "Instance dropped"); }, } on_event(Event::Stopped(config)) }