diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2025-08-26 18:35:54 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2025-08-26 18:35:54 -0400 |
| commit | 17c38585fc2623a6b0196146cf6b6df9955ce979 (patch) | |
| tree | 745729ba55c1b1420181d2885e147aef8eebc913 /src/login/app.rs | |
| parent | a2fee1c18d9def1486a570fb3c98db5372c51238 (diff) | |
Consolidate `events.map(…).collect()` calls into `Broadcaster`.
This conversion, from an iterator of type-specific events (say, `user::Event` or `message::Event`), into a `Vec<event::Event>`, is prevasive, and it needs to be done each time. Having Broadcaster expose a support method for this cuts down on the repetition, at the cost of a slightly alarming amount of type-system nonsense in `broadcast_from`.
Historical footnote: the internal message structure is a Vec and not an individual message so that bulk operations, like expiring channels and messages, won't disconnect everyone if they happen to dispatch more than sixteen messages (current queue depth limit) at once. We trade allocation and memory pressure for keeping the connections alive. _Most_ event publishing is an iterator of one item, so the Vec allocation is redundant.
Diffstat (limited to 'src/login/app.rs')
| -rw-r--r-- | src/login/app.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/login/app.rs b/src/login/app.rs index 77d4ac3..e471000 100644 --- a/src/login/app.rs +++ b/src/login/app.rs @@ -80,9 +80,10 @@ impl<'a> Logins<'a> { tx.tokens().create(&token, &secret).await?; tx.commit().await?; - for event in revoked.into_iter().map(TokenEvent::Revoked) { - self.token_events.broadcast(event); - } + revoked + .into_iter() + .map(TokenEvent::Revoked) + .for_each(|event| self.token_events.broadcast(event)); Ok(secret) } else { |
