sacred / prevent-race-condition
This package allows you to lock some part of code to prevent race condition.
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/sacred/prevent-race-condition
Requires
- php: ^8.0
- psr/cache: ^2.0|^3.0
- psr/simple-cache: ^2.0|^3.0
Requires (Dev)
- phpunit/phpunit: ^9.0
- symfony/cache: ^6.0
README
This package allows you to lock some part of code to prevent race condition.
Install
composer require sacred/prevent-race-condition
Basic usage
You need PSR-6 or PSR-16 cache to use this
use PreventRaceCondition\RaceConditionFactory; // $somePSR16Cache is PSR16 any cache instance $raceCondition = RaceConditionFactory::fromCacheItemPool($somePSR16Cache); // or // $somePSR6Cache is PSR6 any cache instance $raceCondition = RaceConditionFactory::fromSimpleCache($somePSR6Cache); while($raceCondition->isBusy('lock-name')) { // wait or do something else } $raceCondition->lock('lock-name'); // do something $raceCondition->release('lock-name');