| Crates.io | this-state |
| lib.rs | this-state |
| version | 0.3.0 |
| created_at | 2023-06-11 02:22:53.869364+00 |
| updated_at | 2023-12-17 00:54:05.955829+00 |
| description | this-state provides a way to store state in a thread-safe manner as well as a way to asynchronously wait for state changes |
| homepage | https://github.com/tooboredtocode/this-state |
| repository | https://github.com/tooboredtocode/this-state |
| max_upload_size | |
| id | 887175 |
| size | 41,393 |
this-state provides a way to store state in a thread-safe manner as well as a way to asynchronously wait for state changes.
The example below uses the following state:
#[derive(Clone, Debug, PartialEq)]
enum MyState {
A,
B,
C
}
let state = State::new(MyState::A);
let state_clone = state.clone();
tokio::spawn(async move {
// do some work
state_clone.set(MyState::B);
// do some more work
state_clone.set(MyState::C);
});
state.wait_for_state(MyState::C).await;
assert_eq!(state.get(), MyState::C);