Skip to content

Commit

Permalink
better locks for CRUD uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
stevensJourney committed Nov 20, 2023
1 parent 3d81a1f commit 8ff6325
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/dull-radios-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@journeyapps/powersync-sdk-common': patch
---

Added better locking for CRUD uploads
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,26 @@ export abstract class AbstractStreamingSyncImplementation extends BaseObserver<S
}

protected async _uploadAllCrud(): Promise<void> {
this.isUploadingCrud = true;
while (true) {
try {
const done = await this.uploadCrudBatch();
if (done) {
this.isUploadingCrud = false;
break;
return this.obtainLock({
type: LockType.CRUD,
callback: async () => {
this.isUploadingCrud = true;
while (true) {
try {
const done = await this.uploadCrudBatch();
if (done) {
this.isUploadingCrud = false;
break;
}
} catch (ex) {
this.updateSyncStatus(false);
await this.delayRetry();
this.isUploadingCrud = false;
break;
}
}
} catch (ex) {
this.updateSyncStatus(false);
await this.delayRetry();
this.isUploadingCrud = false;
break;
}
}
});
}

protected async uploadCrudBatch(): Promise<boolean> {
Expand Down

0 comments on commit 8ff6325

Please sign in to comment.