Skip to content

bottlebo/MUTEX

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Usage

    const mutex = new Mutex();

runExclusive

  mutex
    .runExclusive([key1,key2,...], function() {
        // ...
    })
    .then(function(result) {
        // ...
    });
Async function example
mutex.runExclusive([key1,key2,...], async () => {
    const i = await store.get();
    await store.put(i + 1);
});

or

mutex.acquire([key1,key2,...], async () => {
    const i = await store.get();
    await store.put(i + 1);
});

Callback example

  mutex
    .acquire([key1,key2,...])
    .then(function(lock) {
        // ...
        mutex.release(lock);
    });

Async example

const lock = await mutex.acquire([key1,key2,...]);
try {
    const i = await store.get();
    await store.put(i + 1);
} finally {
    mutex.release(lock);
}

Checking whether the mutex is locked

mutex.isLocked(key);

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •