Code Monkey home page Code Monkey logo

fcf-framework-lock's Introduction

fcf-framework-lock

Packet provides functions for locking on a file and named mutexes. The package is compatible with UNIX systems and Windows.

Supported OS: UNIX & Windows

The package supports NODEJS version 6 and all following.

Package description page: https://fcf-framework.tech/packages/fcf-framework-lock

lockFile(string a_filePath, function a_cb)

lockFile(number a_fileHandle, function a_cb)

Performs a file lock

  • string a_filePath - The path to the file.
  • number a_fileHandle - The open file handle returned by the FS.open() functions.
  • function a_cb - The function of processing the result of the function execution.
    • Function signature: a_cb(Error|undefined a_error, number a_lock)
      • Error|undefined a_error - If the function executed with an error, then the argument contains an error object
      • number a_lock - Contains a lock handle to be passed to the unlockFile function to unlock the file.

tryLockFile(string a_filePath, function a_cb)

tryLockFile(number a_fileHandle, function a_cb)

tryLockFile(string a_filePath, boolean a_quiet, function a_cb)

tryLockFile(number a_fileHandle, boolean a_quiet, function a_cb)

Performs a lock on the file, if the file already has a lock, the function fails (the "unavailable" property of the error object is set to true)

  • string a_filePath - The path to the file.
  • number a_fileHandle - The open file handle returned by the FS.open() functions.
  • boolean a_quiet = false - If true, then if a lock is held on a file that is already locked, the function exits without error, and the value of the a_lock argument in the callback function is undefined. If the value is not set or is false, then if the file is already locked, the function will fail with an error object containing an "unavailable" field equal to true.
  • function a_cb - The function of processing the result of the function execution.
    • Function signature: a_cb(Error|undefined a_error, number a_lock)
      • Error|undefined a_error - Error object. If the function was locking on an already locked file, then the error object will contain the "unavailable" property set to true.
      • number a_lock - If successful, contains a lock handle that must be passed to the unlockFile function to unlock the file.

unlockFile(number a_lock, function a_cb)

Performs file unlocking

  • number a_lock - The lock handle.
  • function a_cb - The function of processing the result of the function execution.
    • Function signature a_cb: a_cb(Error|undefined a_error)
      • Error|undefined a_error - Error object.

isLockFile(string a_filePath, function a_cb)

isLockFile(number a_fileHandle, function a_cb)

Checks if the file is locked.

  • string a_filePath - The path to the file.
  • number a_fileHandle - The open file handle returned by the FS.open() functions.
  • 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 file has a lock.

lockNamedMutex(string a_name, function a_cb)

Locks a named mutex

  • 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, number a_lock)
      • Error|undefined a_error - If the function executed with an error, then the argument contains an error object
      • number a_lock - Contains a lock handle to be passed to the unlockNamedMutex function to unlock the mutex.

tryLockNamedMutex(string a_name, function a_cb)

tryLockNamedMutex(string a_name, boolean a_quiet, function a_cb)

Tries to lock a named mutex without waiting. If the mutex already has a lock, the function fails (the "unavailable" property of the error object is set to true)

  • string a_name - The mutex name
  • boolean a_quiet = false - If true, then if a lock is held that is already locked, the function exits without error, and the value of the a_lock argument in the callback function is undefined. If the value is not set or is false, then if the mutex is already locked, the function will fail with an error object containing an "unavailable" field equal to true.
  • function a_cb - The function of processing the result of the function execution.
    • Function signature: a_cb(Error|undefined a_error, number a_lock)
      • Error|undefined a_error - Error object. If the function was locking on an already locked mutex, then the error object will contain the "unavailable" property set to true.
      • number a_lock - If successful, contains a lock handle that must be passed to the unlockNamedMutex function to unlock the mutex.

unlockNamedMutex(number a_lock, function a_cb)

Performs a mutex unlock

  • number a_lock - The lock ID obtained by the lockNamedMutex tryLockNamedMutex functions
  • function a_cb - The function of processing the result of the function execution.
    • Function signature a_cb: a_cb(Error|undefined a_error)
      • Error|undefined a_error - Error object.

isLockNamedMutex(string a_name, function a_cb)

Checks whether the named mutex is locked

  • 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.

fcf-framework-lock's People

Contributors

fcf-framework avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.