Skip to content

Commit

Permalink
Manipulate Y.js doc within a dexie transaction to avoid race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
dfahlander committed Jun 19, 2024
1 parent b2e86b0 commit ad6c737
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions test/tests-yjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ promisedTest('Test DexieYProvider', async () => {
/* @type {Y.Doc} */
let doc = row.content;
let provider = new DexieYProvider(doc);
doc.getArray('arr').insert(0, ['a', 'b', 'c']);
await provider.whenLoaded;
// Await the transaction of doc manipulation to not
// bring down the database before it has been stored.
await db.transaction('rw', db.docs, () => {
doc.getArray('arr').insert(0, ['a', 'b', 'c']);
});
//await provider.whenLoaded;
doc.destroy();
db.close({disableAutoOpen: false});
await db.open();
Expand Down

0 comments on commit ad6c737

Please sign in to comment.