message: Allow snapshotting the round_robin
diff: @@ -10,6 +10,7 @@ use std::{
  num::NonZeroUsize,
  };
  +use enum_iterator::IntoEnumIterator;
  use tokio::sync::{Mutex, Semaphore};
  /// Weighted round-robin scheduler.
  @@ -62,6 +63,45 @@ struct Slot<K> {
  tickets: usize,
  }
  +impl<I, K> WeightedRoundRobin<I, K>
  +where
  + I: Clone,
  + K: Copy + Clone + Eq + Hash + IntoEnumIterator,
  +{
  + /// Create a snapshot of the queue by locking it and copying it.
  + ///
  + /// # Warning
  + ///
  + /// This function locks all queues in the order defined by the order defined by
  + /// `IntoEnumIterator`. Calling it multiple times in parallel is safe, but other code that locks
  + /// more than one queue at the same time needs to be aware of this.
  + pub async fn snapshot(&self) -> HashMap<K, Vec<I>> {
  + // Lock all queues in order get a snapshot, but release eagerly. This way we are guaranteed
  + // to have a consistent result, but we also allow for queues to be used again earlier.
  + let mut locks = Vec::new();
  +
  + for kind in K::into_enum_iter() {
  + let queue_guard = self
  + .queues
  + .get(&kind)
  + .expect("missing queue white snapshotting")
  + .lock()
  + .await;
  +
  + locks.push((kind, queue_guard));
  + }
  +
  + let mut output = HashMap::new();
  +
  + // By iterating over the guards, they are dropped in order.
  + for (kind, guard) in locks {
  + output.insert(kind, (*guard).iter().cloned().collect());
  + }
  +
  + output
  + }
  +}
  +
  impl<I, K> WeightedRoundRobin<I, K>
  where
  K: Copy + Clone + Eq + Hash,
  