FCF 2.0 development in progress...
> > > >
[News] [Packages API] [Downloads] [Donate to the project] [Contacts]

fcf.NLock.isLockNamedMutex() function

[SERVER ONLY] fcf.NLock.isLockNamedMutex(string a_name, function a_cb)

Package: fcf-framework-lock

File: fcf-framework-lock:index.js

Available from version: 1.0.6

Checks whether the named mutex is locked

Arguments

string a_name
- The mutex name

function a_cb
- The function of processing the result of the function execution.

Function signature: a_cb(Error|undefined a_error, boolean a_isLocked)

  • Error|undefined a_error - Error object.

  • boolean a_isLocked - true if the mutex has a lock.

Example: Function application

let libLock = require("fcf-framework-lock"); async function main(){ const mutexName = "TestMutexForExample" let isLocked = await new Promise((a_res, a_rej)=>{ libLock.isLockNamedMutex(mutexName, (a_error, a_isLocked)=>{ if (!a_error){ a_res(a_isLocked); } else { a_rej(a_error); } }); }); console.log("Mutex state:", isLocked ? "LOCKED" : "NOT LOCKED"); islocked = await new Promise((a_res, a_rej)=>{ libLock.lockNamedMutex(mutexName, (a_error, a_lock)=>{ if (!a_error){ a_res(a_lock); } else { a_rej(a_error); } }); }); isLocked = await new Promise((a_res, a_rej)=>{ libLock.isLockNamedMutex(mutexName, (a_error, a_isLocked)=>{ if (!a_error){ a_res(a_isLocked); } else { a_rej(a_error); } }); }); console.log("Mutex state:", isLocked ? "LOCKED" : "NOT LOCKED"); } main();

Output:

Mutex state: NOT LOCKED Mutex state: LOCKED