Skip to content

Commit b695882

Browse files
Merge pull request #1236 from carllerche/task-docs
Task docs
2 parents db8b8be + 21a7537 commit b695882

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/task_impl/mod.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,31 @@ fn with<F: FnOnce(&BorrowedTask) -> R, R>(f: F) -> R {
5454
/// the future as notifications arrive, until the future terminates.
5555
///
5656
/// This is obtained by the `task::current` function.
57+
///
58+
/// # FAQ
59+
///
60+
/// ### Why does `Task` not implement `Eq` and `Hash`?
61+
///
62+
/// A valid use case for `Task` to implement these two traits has not been
63+
/// encountered.
64+
///
65+
/// Usually, this question is asked by someone who wants to store a `Task`
66+
/// instance in a `HashSet`. This seems like an obvious way to implement a
67+
/// future aware, multi-handle structure; e.g. a multi-producer channel.
68+
///
69+
/// In this case, the idea is that whenever a `start_send` is called on one of
70+
/// the channel's send handles, if the channel is at capacity, the current task
71+
/// is stored in a set. Then, when capacity is available, a task is removed from
72+
/// the set and notified.
73+
///
74+
/// The problem with this strategy is that multiple `Sender` handles can be used
75+
/// on the same task. In this case, when the second handle is used and the task
76+
/// is stored in a set, there already is an entry. Then, when the first
77+
/// handle is dropped, this entry is cleared, resulting in a dead lock.
78+
///
79+
/// See [here](https://github.com/rust-lang-nursery/futures-rs/issues/670) for
80+
/// more discussion.
81+
///
5782
#[derive(Clone)]
5883
pub struct Task {
5984
id: usize,

0 commit comments

Comments
 (0)