Mutex and adapters 1.0.0
Fisrt version of mutex package was released. This package provides mutex implementation and allows mutual execution of concurrent processes in order to prevent "race conditions". This is achieved by using a "lock" mechanism. Each possibly concurrent processes cooperates by acquiring a lock before accessing the corresponding data.
There are multiple ways you can use the package. You can execute a callback in a synchronized mode i.e. only a single instance of the callback is executed at the same time:
/** @var \Yiisoft\Mutex\Synchronizer $synchronizer */
$newCount = $synchronizer->execute('critical', function () {
return $counter->increase();
}, 10);
Another way is to manually open and close mutex:
/** @var \Yiisoft\Mutex\SimpleMutex $simpleMutex */
if (!$simpleMutex->acquire('critical', 10)) {
throw new \RuntimeException('Unable to acquire mutex "critical".');
}
$newCount = $counter->increase();
$simpleMutex->release('critical');
It could be done on lower level:
/** @var \Yiisoft\Mutex\MutexFactoryInterface $mutexFactory */
$mutex = $mutexFactory->createAndAcquire('critical', 10);
$newCount = $counter->increase();
$mutex->release();
And if you want even more control, you can acquire mutex manually:
/** @var \Yiisoft\Mutex\MutexFactoryInterface $mutexFactory */
$mutex = $mutexFactory->create('critical');
if (!$mutex->acquire(10)) {
throw new \RuntimeException('Unable to acquire mutex "critical".');
}
$newCount = $counter->increase();
$mutex->release();
Additionally, the following adapter packages were released and are available:
As usual for Yii3 packages, this set has a high test coverage, high MSI score, statically checked and well documented.
新闻归档
热门标签
- yii3
- 扩展
- 发布
- yii2
- debug
- auth client
- view
- bootstrap
- html
- release
- redis
- apidoc
- Yii 2.0
- Yii 1.1
- mongodb
- mailer
- extensions
- twig
- gii
- queue
- runner
- http 客户端
- console
- validation
- sphinx
- cache
- widget
- translator
- hydrator
- error handler
- db
- symfonymailer
- log
- http
- config
- assets
- swiftmailer
- 图书
- imagine
- csrf
- elasticsearch
- swagger
- IDE
- i18n
- router
- definitions
- fastroute
- logging
- smarty
- user