Remove instance id generics

Instead, all instance ids are now usize (like message ids). This allows
me to enforce the fact that no two instances of a Bot must have the same
id by generating the ids in the Bot.

Reusing the same id for multiple instances that send their events to the
same place can lead to race conditions depending on how events are
handled. For example, the old instance might still be shutting down
while the new instance is already connected to a room, leading to an
InstanceEvent::Stopped from the old instance that seemingly applies to
the new instance.
This commit is contained in:
Joscha 2024-12-27 14:42:35 +01:00
parent 17ff660ab2
commit 8377695529
4 changed files with 68 additions and 83 deletions

View file

@ -77,7 +77,7 @@ async fn run() -> anyhow::Result<()> {
.instance("test")
.with_username("examplebot");
bot.add_instance((), config);
bot.add_instance(config);
while let Some(event) = bot.recv().await {
if let BotEvent::Packet { conn, packet, .. } = event {

View file

@ -77,7 +77,7 @@ async fn run() -> anyhow::Result<()> {
.with_username("examplebot");
let (event_tx, mut event_rx) = mpsc::channel(10);
let _instance = Instance::new((), config, event_tx); // Don't drop or instance stops
let _instance = Instance::new(0, config, event_tx); // Don't drop or instance stops
while let Some(event) = event_rx.recv().await {
if let InstanceEvent::Packet { conn, packet, .. } = event {