killswitch

Check-in Differences
Login

Check-in Differences

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Difference From killswitch-0.4.1 To killswitch-0.4.2

2024-09-19
10:25
Happy pedantic clippy. check-in: cfdf1b6ecc user: jan tags: trunk
2024-04-07
00:03
Add ability to mark a KillSwitch to trigger-on-drop, and begin working on support for passing a value along with a trigger (and it should be possible to return it when finalizing a KillSwitch). check-in: 04a927872d user: jan tags: trig-val-and-drop
2023-09-17
10:26
Release maintenance. check-in: e0fdaa80c5 user: jan tags: killswitch-0.4.2, trunk
10:23
Add the ability to reset a triggered kill switch. Add changelog. check-in: 5e3b67e904 user: jan tags: trunk
2023-09-16
20:00
Documentation updates. check-in: c86094cf47 user: jan tags: trunk
2023-09-06
04:40
Rearrange excluded files/directories. check-in: 742608f38e user: jan tags: killswitch-0.4.1, trunk
03:12
Code normalization. check-in: 4ca07b05fb user: jan tags: trunk

Changes to .efiles.

1


2
3
4
5
6
Cargo.toml


src/lib.rs
src/pair.rs
src/pair/killtrig.rs
src/pair/killwait.rs
examples/tokselect.rs

>
>





1
2
3
4
5
6
7
8
Cargo.toml
www/index.md
www/changelog.md
src/lib.rs
src/pair.rs
src/pair/killtrig.rs
src/pair/killwait.rs
examples/tokselect.rs

Changes to Cargo.toml.

1
2
3
4
5
6
7
8
9
10
[package]
name = "killswitch"
version = "0.4.1"
authors = ["Jan Danielsson <jan.danielsson@qrnch.com>"]
edition = "2021"
license = "0BSD"
categories = [ "asynchronous" ]
keywords = [ "shutdown", "async"  ]
repository = "https://repos.qrnch.tech/pub/killswitch"
description = "Killswitch used to broadcast a shutdown request."


|







1
2
3
4
5
6
7
8
9
10
[package]
name = "killswitch"
version = "0.4.2"
authors = ["Jan Danielsson <jan.danielsson@qrnch.com>"]
edition = "2021"
license = "0BSD"
categories = [ "asynchronous" ]
keywords = [ "shutdown", "async"  ]
repository = "https://repos.qrnch.tech/pub/killswitch"
description = "Killswitch used to broadcast a shutdown request."
20
21
22
23
24
25
26

27
28
29
30
31
32
[dependencies]
parking_lot = { version = "0.12.1" }

[dev-dependencies]
tokio = { version = "1.32.0", features = [
  "macros", "rt-multi-thread", "time"
] }

tracing = { version = "0.1.37" }
tracing-subscriber = { version = "0.3.17" }

[package.metadata.docs.rs]
rustdoc-args = ["--generate-link-to-definition"]








>






20
21
22
23
24
25
26
27
28
29
30
31
32
33
[dependencies]
parking_lot = { version = "0.12.1" }

[dev-dependencies]
tokio = { version = "1.32.0", features = [
  "macros", "rt-multi-thread", "time"
] }
tokio-test = { version = "0.4.3" }
tracing = { version = "0.1.37" }
tracing-subscriber = { version = "0.3.17" }

[package.metadata.docs.rs]
rustdoc-args = ["--generate-link-to-definition"]

Changes to src/lib.rs.









1
2
3
4
5
6
7








//! Signal a request for (multiple) async tasks to self-terminate.
//!
//! ```
//! use std::error::Error;
//! use tokio::time::{sleep, Duration};
//! use killswitch::KillSwitch;
//!
>
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//! This library provides two separate structures for signalling (and
//! receiveing) termination requests [in `async` contexts]:
//!
//! - [`KillSwitch`] acts as both a trigger and a receiver.
//! - [`pair::KillTrig`] and [`pair::KillWait`] (created using
//!   [`pair::create()`]) act as a kill signal sender and receiver.
//!
//! # KillSwitch
//! Signal a request for (multiple) async tasks to self-terminate.
//!
//! ```
//! use std::error::Error;
//! use tokio::time::{sleep, Duration};
//! use killswitch::KillSwitch;
//!
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133








































134
135
136
137
138
139
140
  pub fn wait(&self) -> WaitFuture {
    WaitFuture {
      ctx: Arc::clone(&self.0),
      id: None
    }
  }


  /// Return a Future that will return `Ready` once there are no more waiters
  /// waiting on this killswitch to be triggered.
  ///
  /// The KillSwitch must be triggered before calling this function, or the
  /// returned future will return an error.
  pub fn finalize(&self) -> FinalizedFuture {
    FinalizedFuture {
      ctx: Arc::clone(&self.0),
      id: None
    }
  }










































  /// Return a boolean indicating whether kill switch has been triggered.
  ///
  /// Returns `true` if kill switch has been triggered.  Returns `false`
  /// otherwise.
  pub fn is_triggered(&self) -> bool {
    self.0.triggered.load(Ordering::SeqCst)







<












>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







122
123
124
125
126
127
128

129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
  pub fn wait(&self) -> WaitFuture {
    WaitFuture {
      ctx: Arc::clone(&self.0),
      id: None
    }
  }


  /// Return a Future that will return `Ready` once there are no more waiters
  /// waiting on this killswitch to be triggered.
  ///
  /// The KillSwitch must be triggered before calling this function, or the
  /// returned future will return an error.
  pub fn finalize(&self) -> FinalizedFuture {
    FinalizedFuture {
      ctx: Arc::clone(&self.0),
      id: None
    }
  }

  /// Reset `KillSwitch`.
  ///
  /// Care should be taken when using this.  Generally speaking it should only
  /// be used immediately following a [`KillSwitch::finalize()`]:
  ///
  /// ```
  /// use killswitch::KillSwitch;
  ///
  /// # tokio_test::block_on(async {
  /// let ks = KillSwitch::default();
  /// assert_eq!(ks.is_triggered(), false);
  ///
  /// // Trigger kill switch
  /// ks.trigger();
  /// assert_eq!(ks.is_triggered(), true);
  /// ks.finalize().await;
  /// ks.reset();
  ///
  /// // KillSwitch became untriggered again
  /// assert_eq!(ks.is_triggered(), false);
  /// # });
  /// ```
  ///
  /// Applications should prefer to call [`KillSwitch::finalize_reset()`]
  /// rather than calling `finalize()` and `reset()`.
  pub fn reset(&self) {
    self.0.triggered.store(false, Ordering::SeqCst);
  }

  /// Finalize and reset `KillSwitch`.
  ///
  /// Returns `Err(())` if the `KillSwitch` wasn't in triggered state.
  pub async fn finalize_reset(&self) -> Result<(), ()> {
    if (self.finalize().await).is_ok() {
      self.reset();
      Ok(())
    } else {
      Err(())
    }
  }

  /// Return a boolean indicating whether kill switch has been triggered.
  ///
  /// Returns `true` if kill switch has been triggered.  Returns `false`
  /// otherwise.
  pub fn is_triggered(&self) -> bool {
    self.0.triggered.load(Ordering::SeqCst)

Added www/changelog.md.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Change Log

## [Unreleased]

### Added

### Changed

### Removed

---

## [0.4.2] - 2023-09-17

[Details](https://repos.qrnch.tech/pub/killswitch/vdiff?from=killswitch-0.4.1&to=killswitch-0.4.2)

### Added

- Add `KillSwitch::reset()` and `KillSwitch::finalize_reset()` to allow a kill
  switch to be reused.

Changes to www/index.md.

1
2
3
4
5














# killswitch

The killswitch is a special-purpose object for signalling multiple tasks
simultaneously that they should self-terminate.




















>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# killswitch

The killswitch is a special-purpose object for signalling multiple tasks
simultaneously that they should self-terminate.


## Change log

The details of changes can always be found in the timeline, but for a
high-level view of changes between released versions there's a manually
maintained [Change Log](./changelog.md).


## Project Status

_killswitch_ is in _maintenance mode_; it is feature-complete with regards to
its initial goal, but will receive bugfixes and improvements to
implementation/documentation.