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

Feat: autocommit transaction #127

Merged
merged 2 commits into from
Oct 30, 2023
Merged

Feat: autocommit transaction #127

merged 2 commits into from
Oct 30, 2023

Conversation

zxch3n
Copy link
Member

@zxch3n zxch3n commented Oct 30, 2023

Transactions are difficult to use in Loro. This PR enables automatic transaction committing.

The previous approach in JS:

const loro = new Loro();
const map = loro.getMap("m");
loro.transact((tx) => {
  map.set(tx, "0", "3");
  map.set(tx, "1", "2");
});

Now, with the transaction block removed:

const loro = new Loro();
const map = loro.getMap("m");
map.set("0", "3");
map.set("1", "2");

Users can still group operations as needed:

const loro = new Loro();
const map = loro.getMap("m");
map.set("0", "0");  // first group
map.set("1", "1");  // first group
loro.commit();
map.set("2", "2");  // second group
map.set("3", "3");  // second group
loro.commit();

The above code achieves the same result as the following previous approach:

const loro = new Loro();
const map = loro.getMap("m");
loro.transact((tx) => {
  map.set("0", "0");  // first group
  map.set("1", "1");  // first group
});
loro.transact((tx) => {
  map.set("2", "3");  // second group
  map.set("3", "3");  // second group
});

Note: WASM events are now triggered after microtasks to prevent recursive locks on Transactions, which currently present a complex challenge. I make it work again ☺️

@zxch3n zxch3n requested a review from Leeeon233 October 30, 2023 09:34
@zxch3n zxch3n changed the title Feat: autocommit transaction WIP: Feat: autocommit transaction Oct 30, 2023
@zxch3n zxch3n changed the title WIP: Feat: autocommit transaction Feat: autocommit transaction Oct 30, 2023
@zxch3n zxch3n merged commit 8293347 into main Oct 30, 2023
1 check passed
@zxch3n zxch3n deleted the feat-wasm-autocommit branch October 30, 2023 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant