Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transactions #7

Closed
paulgb opened this issue Mar 27, 2021 · 1 comment
Closed

Transactions #7

paulgb opened this issue Mar 27, 2021 · 1 comment

Comments

@paulgb
Copy link
Member

paulgb commented Mar 27, 2021

For built-in data structures, it might sometimes be useful to be able to atomically perform multiple operations. I'd need to give some thought to the best way to do this, but one idea is to have a Transactioned pseudo-data structure that wraps a state machine and accepts a Transaction update. Something like (not tested):

pub struct Transaction<T: Transition>(Vec<T>);

pub struct Transactioned<T: StateMachine>(T);

impl<T: StateMachine> StateMachine for Transactioned<T> {
    type Transition = Transactioned<<T as StateMachine>::Transition>;

    fn apply(&mut self, transition: Self::Transition) {
        for t in transition.0 {
            self.0.apply(t);
        }
    }
}
@paulgb
Copy link
Member Author

paulgb commented Nov 17, 2021

The more I think about it, the more I think transactions are the wrong approach. The need for transactions implies that a user intent could result in multiple state transitions, but the correct way to model that is for the user intent to represent one state transition that captures both actions.

@paulgb paulgb closed this as completed Nov 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant