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:
parent
17ff660ab2
commit
8377695529
4 changed files with 68 additions and 83 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue