Description
Hi Team,
I have being trying to get okra to persist in IDB in browser and sync with remote replica using sync protocol, but seem to run into a problem after bunch of fast writes coming from here
okra-js/packages/okra/src/NodeStore.ts
Lines 106 to 112 in eeaceb6
Initially I attempted to use okra-idb package from npm but I was running into lot of problems with IDB transactions completing mid writes. As @joeltg have pointed out here #3 that is because IDB completes transaction as soon as you yield to event loop & async generators do exactly that.
To overcome this problem I have effectively rewrote IDB backend and most of the core okra constructs to use generator based task scheduling library which I have being using already to abstract over sync / async interfaces. General idea is that you can author potentially async logic as follows
Task.spawn(function* () {
const awaited = yield* Task.wait(maybePromise)
....
})
In case of IDB I also have wrote task poll
that just like Task.wait
will suspend execution and resume once passed IDBRequest succeeds or fails. This way I could represent entries / nodes using custom Sequence
type which utilized tasks.
Above switch addressed premature IDB transaction completion issues, as task scheduler ensures that continuations take places on IDBRequest
events without yielding to event-loop.
Unfortunately I am running into the mentioned invariant mentioned at the beginning of the issue. It appears that after some bunch of writes store ends up in a state where iteration over nodes does return an entry where first key isn't a single byte.
Perhaps more surprising is the fact that DB does actually contain record where with 0xFF
key which makes me wonder if iteration order assumed is invalid

I realize that at this point, I'm basically working off a fork but any help would be highly appreciated. I also would be very delighted if any of the ideas could be uplifted to this library.