Is there an order guarantee between the storage.set() and a following storage.get(), or storage.get() will always get the storage area ignoring other storage.set() method?


#1

browser.storage.local.set({
config1: {
“captchaUrl”: “://xxx.xxx.com/get_img”,
“content_script”: “site.js”
}
});
browser.storage.local.get().then(settings => {
let config2=settings[“config1”];
// block02, do something with config here
console.log(config2);
});

Is it guaranteed that the config2 would always get an object rather than undefined?? Or is there an order guarantee that the the storage.get() method above will get the data set by the storage.set() which is followed by storage.get() ?
I have made a test but I coundn’t find any documentation about this.


(Axel) #2

StorageArea.set is async, so no.


#3

async means that StorageArea.set will not block, and the real storing action will work in the background, then the browser.storage.local.get() will be executed immediately, and the real retrieving action will also work in the background. After the real work in the background, both callbacks in then() method will get invoked.
Is the order between the real storing action and the real retrieving action also not guaranteed??


(Martin Giger) #4

No, there is no guarantee of order. Current behavior may have ordering, but that is no API guarantee.

If you need them to happen in order, wait for set until you get again.


#5

:ok_hand:Thanks for your answers.