Options
All
  • Public
  • Public/Protected
  • All
Menu

Class RemoteMutex

Remote Mutex.

author

Jeongho Nam - https://github.com/samchon

Hierarchy

  • RemoteMutex

Index

Methods

lock

  • lock(): Promise<void>
  • Write locks the mutex.

    Monopolies a mutex until be unlocked. If there're someone who have already monopolied or shared the mutex, the function call would be blocked until all of them to return their acquistions by calling unlock or unlock_shared methods.

    In same reason, if you don't call the unlock function after your business, the others who want to monopoly or share the mutex would be fall into the forever sleep. Therefore, never forget to calling the unlock function or utilize the UniqueLock.lock function instead to ensure the safety.

    Returns Promise<void>

lock_shared

  • lock_shared(): Promise<void>

try_lock

  • try_lock(): Promise<boolean>
  • Tries to write lock the mutex.

    Attempts to monopoly a mutex without blocking. If succeeded to monopoly the mutex immediately, it returns true directly. Otherwise there's someone who has already monopolied or shared the mutex, the function gives up the trial immediately and returns false directly.

    Note that, if you succeeded to monopoly the mutex (returns true) but do not call the unlock function after your business, the others who want to monopoly or share the mutex would be fall into the forever sleep. Therefore, never forget to calling the unlock function or utilize the UniqueLock.try_lock function instead to ensure the safety.

    Returns Promise<boolean>

    Whether succeeded to monopoly the mutex or not.

try_lock_for

  • try_lock_for(ms: number): Promise<boolean>
  • Tries to write lock the mutex until timeout.

    Attempts to monopoly a mutex until timeout. If succeeded to monopoly the mutex until the timeout, it returns true. Otherwise failed to acquiring the lock in the given time, the function gives up the trial and returns false.

    Failed to acquiring the lock in the given time (returns false), it means that there's someone who has already monopolied or shared the mutex and does not return it over the timeout.

    Note that, if you succeeded to monopoly the mutex (returns true) but do not call the unlock function after your business, the others who want to monopoly or share the mutex would be fall into the forever sleep. Therefore, never forget to calling the unlock function or utilize the UniqueLock.try_lock_for function instead to ensure the safety.

    Parameters

    • ms: number

      The maximum miliseconds for waiting.

    Returns Promise<boolean>

    Whether succeeded to monopoly the mutex or not.

try_lock_shared

  • try_lock_shared(): Promise<boolean>
  • Tries to read lock the mutex.

    Attemps to share a mutex without blocking. If succeeded to share the mutex immediately, it returns true directly. Otherwise there's someone who has already monopolied the mutex, the function gives up the trial immediately and returns false directly.

    Note that, if you succeeded to share the mutex (returns true) but do not call the unlock_shared function after your buinsess, the others who want to monopoly the mutex would be fall into the forever sleep. Therefore, never forget to calling the unlock_shared function or utilize the SharedLock.try_lock function instead to ensure the safety.

    Returns Promise<boolean>

    Whether succeeded to share the mutex or not.

try_lock_shared_for

  • try_lock_shared_for(ms: number): Promise<boolean>
  • Tries to read lock the mutex until timeout.

    Attemps to share a mutex until timeout. If succeeded to share the mutex until timeout, it returns true. Otherwise failed to acquiring the shared lock in the given time, the function gives up the trial and returns false.

    Failed to acquring the shared lock in the given time (returns false), it means that there's someone who has already monopolied the mutex and does not return it over the timeout.

    Note that, if you succeeded to share the mutex (returns true) but do not call the unlock_shared function after your buinsess, the others who want to monopoly the mutex would be fall into the forever sleep. Therefore, never forget to calling the unlock_shared function or utilize the SharedLock.try_lock_for function instead to ensure the safety.

    Parameters

    • ms: number

      The maximum miliseconds for waiting.

    Returns Promise<boolean>

    Whether succeeded to share the mutex or not.

try_lock_shared_until

  • try_lock_shared_until(at: Date): Promise<boolean>
  • Tries to read lock the mutex until time expiration.

    Attemps to share a mutex until time expiration. If succeeded to share the mutex until time expiration, it returns true. Otherwise failed to acquiring the shared lock in the given time, the function gives up the trial and returns false.

    Failed to acquring the shared lock in the given time (returns false), it means that there's someone who has already monopolied the mutex and does not return it over the time expiration.

    Note that, if you succeeded to share the mutex (returns true) but do not call the unlock_shared function after your buinsess, the others who want to monopoly the mutex would be fall into the forever sleep. Therefore, never forget to calling the unlock_shared function or utilize the SharedLock.try_lock_until function instead to ensure the safety.

    Parameters

    • at: Date

      The maximum time point to wait.

    Returns Promise<boolean>

    Whether succeeded to share the mutex or not.

try_lock_until

  • try_lock_until(at: Date): Promise<boolean>
  • Tries to write lock the mutex until time expiration.

    Attemps to monopoly a mutex until time expiration. If succeeded to monopoly the mutex until the time expiration, it returns true. Otherwise failed to acquiring the lock in the given time, the function gives up the trial and returns false.

    Failed to acquiring the lock in the given time (returns false), it means that there's someone who has already monopolied or shared the mutex and does not return it over the time expiration.

    Note that, if you succeeded to monopoly the mutex (returns true) but do not call the unlock function after your business, the others who want to monopoly or share the mutex would be fall into the forever sleep. Therefore, never forget to calling the unlock function or utilize the UniqueLock.try_lock_until function instead to ensure the safety.

    Parameters

    • at: Date

      The maximum time point to wait.

    Returns Promise<boolean>

    Whether succeeded to monopoly the mutex or not.

unlock

  • unlock(): Promise<void>
  • Write unlocks the mutex.

    When you call this unlock method and there're someone who are currently blocked by attempting to write or read lock this mutex, one of them (FIFO; first-in-first-out) would acquire the lock and continues its execution.

    Otherwise, there's not anyone who is acquiring the write lock of this mutex, the DomainError exception would be thrown.

    As you know, when you succeeded to acquire the write lock, you don't have to forget to calling this unlock method after your business. If you forget it, it would be a terrible situation for the others who're attempting to lock this mutex.

    However, if you utilize the UniqueLock, you don't need to consider about this unlock method. Just define your business into a callback function as a parameter of methods of the UniqueLock, then this unlock method would be automatically called by the UniqueLock after the business.

    throw

    DomainError when no one is acquiring the write lock.

    Returns Promise<void>

unlock_shared

  • unlock_shared(): Promise<void>
  • Read unlocks the mutex.

    When you call this unlock_shared method and there're someone who are currently blocked by attempting to monopoly this mutex, one of them (FIFO; first-in-first-out) would acquire the lock and continues its execution.

    Otherwise, there's not anyone who is acquiring the read lock of this mutex, the DomainError exception would be thrown.

    As you know, when you succeeded to acquire the read lock, you don't have to forget to calling this unlock_shared method after your business. If you forget it, it would be a terrible situation for the others who're attempting to lock this mutex.

    However, if you utilize the SharedLock, you don't need to consider about this unlock_shared method. Just define your business into a callback function as a parameter of methods of the SharedLock, then this unlock_shared method would be automatically called by the SharedLock after the business.

    Returns Promise<void>

Generated using TypeDoc