Skip to content

tooboredtocode/this-state

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

this-state

this-state provides a way to store state in a thread-safe manner as well as a way to asynchronously wait for state changes.

Examples

The example below uses the following state:

#[derive(Clone, Debug, PartialEq)]
enum MyState {
    A,
    B,
    C
}

Waiting for a state change

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);

About

this-state provides a way to store state in a thread-safe manner as well as a way to asynchronously wait for state changes.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Languages