1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//! # `notify` channel
//!
//! This small module implements a simple notification channel which wraps
//! [`tokio::sync::mpsc`] to provide the additional property that if multiple
//! notifications are sent before the receiver calls [`Receiver::recv`], the
//! receiver will only be notified once, preventing the receiver from
//! accidentally doing duplicate work.
//!
//! Everything else is sugar:
//!
//! - Just do `tx.send()` instead of `let _ = tx.try_send(())` to send a
//! notification without caring about if the channel was full or if the
//! receiver was dropped.
//! - Just do `rx.recv()` instead of `if let Some(()) = rx.recv() {}` to check
//! that the future didn't complete simple because the sender was dropped. If
//! all senders have been dropped, this future will never resolve.
//! - Just do `rx.clear()` instead of `while self.rx.try_recv().is_ok() {}` to
//! clear out pending notifications on the channel.
//!
//! This can also be used as a [`oneshot::channel::<()>()`]
//!
//! [`Receiver::recv`]: crate::notify::Receiver::recv
//! [`oneshot::channel::<()>()`]: tokio::sync::oneshot::channel
use mpsc;
/// Create a new `notify` channel returning a [`Sender`] (cloneable) and
/// [`Receiver`] (not cloneable), analogous to `mpsc::channel(1)`.
/// `notify` sender, analogous to `mpsc::Sender<()>`.
>);
/// `notify` receiver, analogous to `mpsc::Receiver<()>`.
>);