Skip to content

Commit af434e1

Browse files
taiki-ecramertj
authored andcommitted
Add docs for ArcWake -> Waker conversion
1 parent e597a6c commit af434e1

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

futures-util/src/task/arc_wake.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,31 @@ use alloc::sync::Arc;
33
/// A way of waking up a specific task.
44
///
55
/// By implementing this trait, types that are expected to be wrapped in an `Arc`
6-
/// can be converted into `Waker` objects.
6+
/// can be converted into [`Waker`] objects.
77
/// Those Wakers can be used to signal executors that a task it owns
88
/// is ready to be `poll`ed again.
9+
///
10+
/// Currently, there are two ways to convert `ArcWake` into [`Waker`]:
11+
///
12+
/// * [`waker`](crate::task::waker()) converts `Arc<impl ArcWake>` into [`Waker`].
13+
/// * [`waker_ref`](crate::task::waker_ref()) converts `&Arc<impl ArcWake>` into [`WakerRef`] that
14+
/// provides access to a [`&Waker`][`Waker`].
15+
///
16+
/// [`Waker`]: std::task::Waker
17+
/// [`WakerRef`]: crate::task::WakerRef
918
// Note: Send + Sync required because `Arc<T>` doesn't automatically imply
1019
// those bounds, but `Waker` implements them.
1120
pub trait ArcWake: Send + Sync {
1221
/// Indicates that the associated task is ready to make progress and should
1322
/// be `poll`ed.
1423
///
1524
/// This function can be called from an arbitrary thread, including threads which
16-
/// did not create the `ArcWake` based `Waker`.
25+
/// did not create the `ArcWake` based [`Waker`].
1726
///
1827
/// Executors generally maintain a queue of "ready" tasks; `wake` should place
1928
/// the associated task onto this queue.
29+
///
30+
/// [`Waker`]: std::task::Waker
2031
fn wake(self: Arc<Self>) {
2132
Self::wake_by_ref(&self)
2233
}
@@ -25,12 +36,14 @@ pub trait ArcWake: Send + Sync {
2536
/// be `poll`ed.
2637
///
2738
/// This function can be called from an arbitrary thread, including threads which
28-
/// did not create the `ArcWake` based `Waker`.
39+
/// did not create the `ArcWake` based [`Waker`].
2940
///
3041
/// Executors generally maintain a queue of "ready" tasks; `wake_by_ref` should place
3142
/// the associated task onto this queue.
3243
///
33-
/// This function is similar to `wake`, but must not consume the provided data
44+
/// This function is similar to [`wake`](ArcWake::wake), but must not consume the provided data
3445
/// pointer.
46+
///
47+
/// [`Waker`]: std::task::Waker
3548
fn wake_by_ref(arc_self: &Arc<Self>);
3649
}

0 commit comments

Comments
 (0)