Skip to content

Commit f624f2d

Browse files
Rollup merge of #128064 - ijackson:noop-waker-doc, r=workingjubilee
Improve docs for Waker::noop and LocalWaker::noop * Add a warning about a likely misuse. (See my commit message for longer rationale.) * Apply some probably-accidentally-omitted changes to `LocalWaker`'s docs * Add a comment about the clone-and-hack of the docs I have used [semantic linefeeds](https://rhodesmill.org/brandon/2012/one-sentence-per-line/) for the docs formatting.
2 parents 4b7d074 + 9a95573 commit f624f2d

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

library/core/src/task/wake.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -530,10 +530,18 @@ impl Waker {
530530

531531
/// Returns a reference to a `Waker` that does nothing when used.
532532
///
533+
// Note! Much of the documentation for this method is duplicated
534+
// in the docs for `LocalWaker::noop`.
535+
// If you edit it, consider editing the other copy too.
536+
//
533537
/// This is mostly useful for writing tests that need a [`Context`] to poll
534538
/// some futures, but are not expecting those futures to wake the waker or
535539
/// do not need to do anything specific if it happens.
536540
///
541+
/// More generally, using `Waker::noop()` to poll a future
542+
/// means discarding the notification of when the future should be polled again.
543+
/// So it should only be used when such a notification will not be needed to make progress.
544+
///
537545
/// If an owned `Waker` is needed, `clone()` this one.
538546
///
539547
/// # Examples
@@ -783,12 +791,22 @@ impl LocalWaker {
783791
Self { waker }
784792
}
785793

786-
/// Creates a new `LocalWaker` that does nothing when `wake` is called.
794+
/// Returns a reference to a `LocalWaker` that does nothing when used.
787795
///
796+
// Note! Much of the documentation for this method is duplicated
797+
// in the docs for `Waker::noop`.
798+
// If you edit it, consider editing the other copy too.
799+
//
788800
/// This is mostly useful for writing tests that need a [`Context`] to poll
789801
/// some futures, but are not expecting those futures to wake the waker or
790802
/// do not need to do anything specific if it happens.
791803
///
804+
/// More generally, using `LocalWaker::noop()` to poll a future
805+
/// means discarding the notification of when the future should be polled again,
806+
/// So it should only be used when such a notification will not be needed to make progress.
807+
///
808+
/// If an owned `LocalWaker` is needed, `clone()` this one.
809+
///
792810
/// # Examples
793811
///
794812
/// ```

0 commit comments

Comments
 (0)