-
Notifications
You must be signed in to change notification settings - Fork 2
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
Fix okra-idb nodes and entries to handle null transaction OK #3
Comments
For context, I'm developing an HTTP server whose API supports a |
The fundamental issue here is with IndexedDB, where transactions auto-commit as soon as they reach zero scheduled operations. Transaction operations are async, but you can't hold the transaction open for arbitrarily long. You can make a series of async operations as long as you start each one in the same event loop tick that the last one resolved in, but as soon as there are no scheduled ticks the transaction closes itself and will throw an error if you try to use it again. A lot of awkwardness within Anyway, the way this is relates here is that your patch is correct and it'll work great AS LONG AS you don't I had left this as a TODO because I wasn't sure if there was a different way I could arrange this that didn't have this limitation... for now I guess I'll just do the thing you did and document the constraint. |
More generally: to use interface Source {
getRoot(): Awaitable<Node>
getNode(level: number, key: Key): Awaitable<Node | null>
getChildren(level: number, key: Key): Awaitable<Node[]>
} So in order to sync server-to-browser, where the browser acts as the "server" and the server acts as the "client", you need to make Also, those three methods are already methods on the |
That's an interesting note about the HTTP server needing to make requests of the browser. I hadn't noticed it in my testing but I admit my testing wasn't exactly rigorous. I'll look into using WebRTC or such. |
The
nodes
andentries
methods on okra-idb's IDBTree contain this worrying comment:The absence of logic for handling a null transaction means that methods like
sync
fail, like this:I've prototyped a simple fix, but I'm not familiar with the ins and outs of this project enough to add tests and such.
That seems to do the trick on my machine, for whatever that's worth. Not sure if there are more complicated caveats lurking in the details.
The text was updated successfully, but these errors were encountered: