-
Notifications
You must be signed in to change notification settings - Fork 12
Description
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.