//! The active Account first: a Friend's import makes each of its requests only while the //! follower has no Riot work running and no finished game waits for its Match. Both wait out //! the relay's `Retry-After` when its quota is full. use std::sync::PoisonError; use crate::tracker::Tracker; /// The follower is at work (a round, a refresh) until this is dropped, also by a panic. pub(super) struct FollowerBusy<'a>(&'a Tracker); impl Drop for FollowerBusy<'_> { fn drop(&mut self) { self.0.follow().busy -= 1; self.0.follower_idle.notify_all(); } } impl Tracker { pub(super) fn follower_busy(&self) -> FollowerBusy<'_> { self.follow().busy += 1; FollowerBusy(self) } /// Blocks while a round or a refresh runs, or while the Match of a finished game is still /// awaited (up to `MATCH_RETRIES` rounds), so that the active Account's requests go first. /// Sleeps on `follower_idle`, which the end of each round signals: no polling. Never call it /// from the follower's thread, whose rounds it waits for. pub(crate) fn wait_for_follower(&self) { let mut follow = self.follow(); while follow.busy > 0 || !follow.pending.is_empty() { follow = (self.follower_idle.wait(follow)).unwrap_or_else(PoisonError::into_inner); } } }