Skip to content

Support for atomic operations #1

@sicking

Description

@sicking

The current API doesn't enable doing things like "add 1 to the value of the a property". Consider the following code

var storage = ...;
storage.get("a").then(function(v) {
  storage.set("a", v+1);
});

If the user has the same page open in two tabs, the above code risks that both tabs reads the same value from "a", and then whichever tab runs the set operation first will have it's value overwritten by the other tab.

Two possible solutions for this is sketched up in my comment here:
https://hacks.mozilla.org/2012/03/there-is-no-simple-solution-for-local-storage/comment-page-1/#comment-1411394

Unfortunately neither solution fits really well with how Futures work since there is additional state carried in addition to the returned value. I.e. a callback behaves differently if it is registered before the Future is resolved or if it is registered after the Future is resolved. This obviously would be a bit of a violation of the Future API.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions