Repository: tokio-rs/tokio
File: tokio/src/task/coop/mod.rs (Rust)

Code before:
    /// use std::pin::Pin;
    /// use std::task::{ready, Context, Poll, Waker};
    /// use tokio::task::coop;
    ///
    /// struct CountdownLatch<T> {
    ///     counter: usize,
    ///     value: Option<T>,
    ///     waker: Option<Waker>
    /// }
    ///
    /// impl<T> CountdownLatch<T> {
    ///     fn new(value: T, count: usize) -> Self {
    ///         CountdownLatch {
    ///             counter: count,
    ///             value: Some(value),
    ///             waker: None
    ///         }
    ///     }
    ///     fn count_down(&mut self) {
    ///         if self.counter <= 0 {
    ///             return;
    ///         }
    ///
    ///         self.counter -= 1;
    ///         if self.counter == 0 {
    ///             if let Some(w) = std::mem::replace(&mut self.waker, None) {
    ///                 w.wake();
    ///             }
    ///         }
    ///     }
    /// }
    ///
    /// impl<T> Future for CountdownLatch<T> where T: Unpin {
    ///       type Output = T;
    ///
    ///       fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
    ///           // `poll_proceed` checks with the runtime if this task is still allowed to proceed
    ///           // with performing work.
    ///           // If not, `Pending` is returned and `ready!` ensures this function returns.
    ///           // If we are allowed to proceed, coop now represents the budget consumption
    ///           let coop = ready!(coop::poll_proceed(cx));
    ///
    ///           // Get a mutable reference to the unpinned CountdownLatch
    ///           let this = Pin::get_mut(self);
    ///
    ///           // Next we check if the latch is ready to release its value
    ///           if this.counter == 0 {
    ///                let t = std::mem::replace(&mut this.value, None);
    ///                // The latch made progress so call `made_progress` to ensure the budget
    ///                // is not reverted.
    ///                coop.made_progress();

Review comment (suggestion):
```suggestion
    ///             if let Some(w) = self.waker.take() {
```

Code after:
    /// use std::pin::Pin;
    /// use std::task::{ready, Context, Poll, Waker};
    /// use tokio::task::coop;
    ///
    /// struct CountdownLatch<T> {
    ///     counter: usize,
    ///     value: Option<T>,
    ///     waker: Option<Waker>
    /// }
    ///
    /// impl<T> CountdownLatch<T> {
    ///     fn new(value: T, count: usize) -> Self {
    ///         CountdownLatch {
    ///             counter: count,
    ///             value: Some(value),
    ///             waker: None
    ///         }
    ///     }
    ///     fn count_down(&mut self) {
    ///         if self.counter <= 0 {
    ///             return;
    ///         }
    ///
    ///         self.counter -= 1;
    ///         if self.counter == 0 {
    ///             if let Some(w) = self.waker.take() {
    ///                 w.wake();
    ///             }
    ///         }
    ///     }
    /// }
    ///
    /// impl<T> Future for CountdownLatch<T> {
    ///     type Output = T;
    ///
    ///     fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
    ///         // `poll_proceed` checks with the runtime if this task is still allowed to proceed
    ///         // with performing work.
    ///         // If not, `Pending` is returned and `ready!` ensures this function returns.
    ///         // If we are allowed to proceed, coop now represents the budget consumption
    ///         let coop = ready!(coop::poll_proceed(cx));
    ///
    ///         // Get a mutable reference to the CountdownLatch
    ///         let this = Pin::get_mut(self);
    ///
    ///         // Next we check if the latch is ready to release its value
    ///         if this.counter == 0 {
    ///             let t = this.value.take();
    ///             // The latch made progress so call `made_progress` to ensure the budget
    ///             // is not reverted.
    ///             coop.made_progress();