Skip to content

Commit

Permalink
Dexie cloud bugfix: Invalid returned promise when waiting for a write…
Browse files Browse the repository at this point in the history
…r to complete its execution.

The issue was hit in repro of #1359.
  • Loading branch information
dfahlander committed Jul 14, 2021
1 parent 73e7c4f commit 44df201
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions addons/dexie-cloud/src/middleware-helpers/guardedTable.ts
Expand Up @@ -28,7 +28,7 @@ function readLock<TReq extends { trans: DBCoreTransaction }, TRes>(
req.trans[prop] || (req.trans[prop] = { writers: [], readers: [] });
const numWriters = writers.length;
const promise = (numWriters > 0
? writers[numWriters - 1].finally(() => fn(req))
? writers[numWriters - 1].then(() => fn(req), () => fn(req))
: fn(req)
).finally(() => readers.splice(readers.indexOf(promise)));
readers.push(promise);
Expand All @@ -47,7 +47,7 @@ function writeLock<TReq extends { trans: DBCoreTransaction }, TRes>(
}: { writers: Promise<any>[]; readers: Promise<any>[] } =
req.trans[prop] || (req.trans[prop] = { writers: [], readers: [] });
let promise = (writers.length > 0
? writers[writers.length - 1].finally(() => fn(req))
? writers[writers.length - 1].then(() => fn(req), () => fn(req))
: readers.length > 0
? allSettled(readers).then(() => fn(req))
: fn(req)
Expand Down

0 comments on commit 44df201

Please sign in to comment.