Manage concurrency between browser tabs running independent processes by (a)synchronizing the localStorage resource.
This is the implementation by Benjamin Dumke-von der Ehe as posted in his 2012 article JavaScript concurrency and locking the HTML5 localStorage.
- Corrects an oversight in the original implementation. Whereas the original implementation hard-coded the "delay" parameter, this fork's implementation makes it user-configurable, per the spec. For more on the delay parameter, refer to the original paper, on page 5: http://research.microsoft.com/en-us/um/people/lamport/pubs/fast-mutex.pdf.
- It abstracts away
localStorage, and instead makes the user responsible for passing in a storage mechanism that is compatible with store.js.
bower install lockablestorage
or
npm install lockable-storage
import createLocker from 'lockable-storage';
import store from 'store';
const locker = createLockableStorage(store);
locker.lock('key', function () {
// exclusive access to localStorage['key']
});