Instead of calling Context::execute which requires exclusive access to a Context to evaluate the command and update the underlying snapshot, a new method, Context::transaction can be defined that initialises a ContextTransaction that stores its own ContextDelta, variable scope and an immutable reference to the Context. Like execute, Context::transaction will take a &str for the command but only require &self. It will also return a ContextDelta as well as the String containing the output of the command, dropping the ContextTransaction internally.
The method, Context::commit could then be changed to take a ContextDelta and apply this to the ContextSnapshot.
This will allow commands to be "simulated" without commiting changes and also commands to be executed in parallel and committed after all commands have finished (although need to think about changing the structure of ContextDelta to detect conflicting changes)
Instead of calling
Context::executewhich requires exclusive access to aContextto evaluate the command and update the underlying snapshot, a new method,Context::transactioncan be defined that initialises aContextTransactionthat stores its ownContextDelta, variable scope and an immutable reference to theContext. Likeexecute,Context::transactionwill take a&strfor the command but only require&self. It will also return aContextDeltaas well as theStringcontaining the output of the command, dropping theContextTransactioninternally.The method,
Context::commitcould then be changed to take aContextDeltaand apply this to theContextSnapshot.This will allow commands to be "simulated" without commiting changes and also commands to be executed in parallel and committed after all commands have finished (although need to think about changing the structure of ContextDelta to detect conflicting changes)