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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//! Stop-tokens are used to signal a sender-chain to stop processing early.
//!
//! If you come from a `go` background, this would be comparable to [Context](https://pkg.go.dev/context#Context).
//!
//! You can create a [StopSource], and then test when it's stopped:
//! ```
//! use senders_receivers::stop_token::*;
//!
//! let source = StopSource::default(); // A source can be stopped.
//!
//! let token = source.token();
//! assert!(!token.stop_requested()); // The token is used to observe the source.
//!
//! // Once the source is stopped, the token will reflect this:
//! source.request_stop();
//! assert!(token.stop_requested());
//! ```
//!
//! A [StopSource] can also accept callbacks, to be invoked when a stop is requested:
//! ```
//! use senders_receivers::stop_token::*;
//!
//! let source = StopSource::default(); // A source can be stopped.
//!
//! let token = source.token();
//! let my_callback = token.callback(|| println!("the source was stopped"));
//!
//! source.request_stop(); // Prints "the source was stopped".
//! ```
//!
//! # Bugs
//! This should really be a separate crate. :/
pub use NeverStopToken;
pub use ;
/// A stop-token keeps track of if a sender-chain has been requested to stop.
///
/// Stop-tokens allow two ways of checking if an operation has been stopped:
/// - by inspecting the [StopToken::stop_requested] method
/// - by installing a callback that'll be invoked once a stop is requested
/// Callback implementation.
///
/// This holds on to the callback function, and deregisters it when this [StopCallback] goes out of scope (unless you call [StopCallback::detach].
///
/// Callbacks implement [Default], which creates a callback without an associated function.