Closed inexorabletash closed 7 years ago
If we are OK picking a default, it could be a boolean (either shared: true
or exclusive: true
). Assuming we don't anticipate more than two modes.
I'm not sure I fully understand this property though (having read the README paragraph and not the linked Wikipedia article) so I should probably do so before answering the actual question.
The idea is that write transactions generally need to have an "exclusive" lock, so nothing else can read and write at the same time. Whereas read transactions can happen concurrently with other read transactions, so they're "shared".
{exclusive: true}
as an optional 2nd arg sounds good to me, where exclusive
defaults to false.
Making exclusive optional/default=false seems weird to me. If every call used that setting, the API would be a no-op. If you're thinking about using this API to implement a "mutex" then exclusive is the only setting you'd want, never shared.
I guess I'd argue for keeping the mode it as-is (non-optional) since it makes the developer reason about the behavior they want. I'd be okay with {shared:true}
.
In IDB "read" is the default, which is why I went for "shared" default, but you're right.
Right now the API requires both
scope
andmode
to be specified as arguments. Should we defaultmode
to"exclusive"
and move it into theoptions
bag?