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

Make batches atomic #1

Open
fewkz opened this issue Nov 11, 2022 · 0 comments
Open

Make batches atomic #1

fewkz opened this issue Nov 11, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@fewkz
Copy link
Owner

fewkz commented Nov 11, 2022

We could make batches atomic, so that none of the changes are committed until the end of the batch. Any errors that occur during a batch will roll back the changes. This would make errors that occur during a batch more predictable, because currently it will put the derived cells in an invalid state, since the batch that's responsible for updating derived cells failed.

local c = cell(0)
pcall(batch, function()
    c.value = 1
    error("An error occured!")
end)
print(c.value) -- Will print 0, since there was an error during the batch operation.

Batches should be able to be nested and each nested batch should be atomic as well.

local c = cell(0)
batch(function()
    pcall(batch, function()
        c.value = 1
        error("An error occured!")
    end)
    print(c.value) -- Will print 0, since there was an error during the batch operation
end

We should consider making it so reading a value inside of a batch should give whatever the value last was set to in that batch. However this isn't strictly necessary, and might just make it confusing when trying to see why the value of a cell seemingly got reverted.

local c = cell(0)
pcall(batch, function()
    c.value = 1
    print(c.value) -- Will print 1
    error("An error occured!")
end)
print(c.value) -- Will print 0, since there was an error during the batch operation.
@fewkz fewkz added the enhancement New feature or request label Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant