Skip to content

Commit 00bf5ee

Browse files
authored
sync: improve watch docs (#5261)
1 parent 8751010 commit 00bf5ee

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

tokio/src/sync/watch.rs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
//! # Usage
1010
//!
1111
//! [`channel`] returns a [`Sender`] / [`Receiver`] pair. These are the producer
12-
//! and sender halves of the channel. The channel is created with an initial
12+
//! and consumer halves of the channel. The channel is created with an initial
1313
//! value. The **latest** value stored in the channel is accessed with
1414
//! [`Receiver::borrow()`]. Awaiting [`Receiver::changed()`] waits for a new
15-
//! value to sent by the [`Sender`] half.
15+
//! value to be sent by the [`Sender`] half.
1616
//!
1717
//! # Examples
1818
//!
@@ -90,10 +90,11 @@ pub struct Sender<T> {
9090
/// Returns a reference to the inner value.
9191
///
9292
/// Outstanding borrows hold a read lock on the inner value. This means that
93-
/// long lived borrows could cause the produce half to block. It is recommended
94-
/// to keep the borrow as short lived as possible. Additionally, if you are
93+
/// long-lived borrows could cause the producer half to block. It is recommended
94+
/// to keep the borrow as short-lived as possible. Additionally, if you are
9595
/// running in an environment that allows `!Send` futures, you must ensure that
96-
/// the returned `Ref` type is never held alive across an `.await` point.
96+
/// the returned `Ref` type is never held alive across an `.await` point,
97+
/// otherwise, it can lead to a deadlock.
9798
///
9899
/// The priority policy of the lock is dependent on the underlying lock
99100
/// implementation, and this type does not guarantee that any particular policy
@@ -350,11 +351,12 @@ impl<T> Receiver<T> {
350351
/// [`changed`] may return immediately even if you have already seen the
351352
/// value with a call to `borrow`.
352353
///
353-
/// Outstanding borrows hold a read lock. This means that long lived borrows
354-
/// could cause the send half to block. It is recommended to keep the borrow
355-
/// as short lived as possible. Additionally, if you are running in an
356-
/// environment that allows `!Send` futures, you must ensure that the
357-
/// returned `Ref` type is never held alive across an `.await` point.
354+
/// Outstanding borrows hold a read lock on the inner value. This means that
355+
/// long-lived borrows could cause the producer half to block. It is recommended
356+
/// to keep the borrow as short-lived as possible. Additionally, if you are
357+
/// running in an environment that allows `!Send` futures, you must ensure that
358+
/// the returned `Ref` type is never held alive across an `.await` point,
359+
/// otherwise, it can lead to a deadlock.
358360
///
359361
/// The priority policy of the lock is dependent on the underlying lock
360362
/// implementation, and this type does not guarantee that any particular policy
@@ -401,11 +403,12 @@ impl<T> Receiver<T> {
401403
/// will not return immediately until the [`Sender`] has modified the shared
402404
/// value again.
403405
///
404-
/// Outstanding borrows hold a read lock. This means that long lived borrows
405-
/// could cause the send half to block. It is recommended to keep the borrow
406-
/// as short lived as possible. Additionally, if you are running in an
407-
/// environment that allows `!Send` futures, you must ensure that the
408-
/// returned `Ref` type is never held alive across an `.await` point.
406+
/// Outstanding borrows hold a read lock on the inner value. This means that
407+
/// long-lived borrows could cause the producer half to block. It is recommended
408+
/// to keep the borrow as short-lived as possible. Additionally, if you are
409+
/// running in an environment that allows `!Send` futures, you must ensure that
410+
/// the returned `Ref` type is never held alive across an `.await` point,
411+
/// otherwise, it can lead to a deadlock.
409412
///
410413
/// The priority policy of the lock is dependent on the underlying lock
411414
/// implementation, and this type does not guarantee that any particular policy
@@ -794,9 +797,12 @@ impl<T> Sender<T> {
794797

795798
/// Returns a reference to the most recently sent value
796799
///
797-
/// Outstanding borrows hold a read lock. This means that long lived borrows
798-
/// could cause the send half to block. It is recommended to keep the borrow
799-
/// as short lived as possible.
800+
/// Outstanding borrows hold a read lock on the inner value. This means that
801+
/// long-lived borrows could cause the producer half to block. It is recommended
802+
/// to keep the borrow as short-lived as possible. Additionally, if you are
803+
/// running in an environment that allows `!Send` futures, you must ensure that
804+
/// the returned `Ref` type is never held alive across an `.await` point,
805+
/// otherwise, it can lead to a deadlock.
800806
///
801807
/// # Examples
802808
///

0 commit comments

Comments
 (0)