haskel / mutex
Mutex Component
dev-master / 0.1.x-dev
2019-06-18 10:23 UTC
This package is auto-updated.
Last update: 2024-11-14 21:17:07 UTC
README
The Mutex component provides the ability to manage locks while accessing the resource at the same time.
Installation
composer require haskel/mutex
Usage
Basic usage
use Haskel\Component\Mutex\MutexManager; use Haskel\Component\Mutex\Mutex\PlainMutex; $mutexManager = new MutexManager(); $mutex = new PlainMutex('SOME_UNIQUE_STRING'); $mutexManager->acquire($mutex); //some actions $mutexManager->release($mutex);
To release everytime if exception throws
use Haskel\Component\Mutex\MutexManager; use Haskel\Component\Mutex\Mutex\PlainMutex; $mutexManager = new MutexManager(); $mutex = new PlainMutex('SOME_UNIQUE_STRING'); $mutexManager->acquire($mutex); //some actions try { //some actions } finally { $mutexManager->release($mutex); }
Try to acquire within 20 seconds
use Haskel\Component\Mutex\MutexManager; use Haskel\Component\Mutex\Mutex\PlainMutex; $mutexManager = new MutexManager(); $mutex = new PlainMutex('SOME_UNIQUE_STRING'); $mutexManager->acquire($mutex, 20); // .......