Repository: tokio-rs/tokio
File: tokio/src/sync/semaphore.rs (Rust)

Code before:
///         // refills the tokens at the end of each interval
///         let jh = tokio::spawn({
///             let sem = sem.clone();
///             let mut interval = interval(duration);
///             interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);
///
///             async move {
///                 loop {
///                     interval.tick().await;
///
///                     if sem.available_permits() < capacity {
///                         sem.add_permits(1);
///                     }
///                 }
///             }
///         });
///
///         Self { jh, sem }
///     }
///
///     async fn acquire(&self) {
///         // This can return an error if the semaphore is closed, but we
///         // never close it, so this error can never happen.
///         let permit = self.sem.acquire().await.unwrap();
///         // To avoid releasing the permit back to the semaphore, we use
///         // the `Permit::forget` method.
///         permit.forget();
///     }
/// }
///
/// impl Drop for TokenBucket {
///     fn drop(&mut self) {
///         // Kill the background task so it stops taking up resources when we
///         // don't need it anymore.
///         self.jh.abort();
///     }
/// }
///
/// #[tokio::main]
/// # async fn _hidden() {}
/// # #[tokio::main(flavor = "current_thread", start_paused = true)]
/// async fn main() {
///     let capacity = 5;
///     let update_interval = Duration::from_secs_f32(1.0 / capacity as f32);
///     let bucket = TokenBucket::new(update_interval, capacity);
///
///     for _ in 0..5 {
///         bucket.acquire().await;
///
///         // do the operation
///     }

Review comment (suggestion):
```suggestion
///         // the `SemaphorePermit::forget` method.
```

Code after:
///         // refills the tokens at the end of each interval
///         let jh = tokio::spawn({
///             let sem = sem.clone();
///             let mut interval = interval(duration);
///             interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);
///
///             async move {
///                 loop {
///                     interval.tick().await;
///
///                     if sem.available_permits() < capacity {
///                         sem.add_permits(1);
///                     }
///                 }
///             }
///         });
///
///         Self { jh, sem }
///     }
///
///     async fn acquire(&self) {
///         // This can return an error if the semaphore is closed, but we
///         // never close it, so this error can never happen.
///         let permit = self.sem.acquire().await.unwrap();
///         // To avoid releasing the permit back to the semaphore, we use
///         // the `SemaphorePermit::forget` method.
///         permit.forget();
///     }
/// }
///
/// impl Drop for TokenBucket {
///     fn drop(&mut self) {
///         // Kill the background task so it stops taking up resources when we
///         // don't need it anymore.
///         self.jh.abort();
///     }
/// }
///
/// #[tokio::main]
/// # async fn _hidden() {}
/// # #[tokio::main(flavor = "current_thread", start_paused = true)]
/// async fn main() {
///     let capacity = 5;
///     let update_interval = Duration::from_secs_f32(1.0 / capacity as f32);
///     let bucket = TokenBucket::new(update_interval, capacity);
///
///     for _ in 0..5 {
///         bucket.acquire().await;
///
///         // do the operation
///     }