Pattern to synchronize access to chrome.storage across multiple background
and content scripts
I am writing a chrome extension with multiple background scripts and
content scripts.
They all share data across chrome.storage, using structures like:
chrome.storage.sync.get("objectname", function(result){
result.object.manipulateObject();
chrome.storage.sync.set({"pendingOrders" : result.pendingOrders});
});
Now this is a textbook case for concurrency problems. Consider the
following scenario:
background.js gets object from storage
background.js manipulates object
content.js gets the same object from storage
background.js writes manipulated object back to storage
content.js manipulates object and writes it back to storage
As a result, the work of background.js is lost.
What is the best pattern to avoid this?
No comments:
Post a Comment