tbachert/sync
最新稳定版本:v1.0.1
Composer 安装命令:
composer require tbachert/sync
包简介
Synchronization primitives
README 文档
README
Installation
composer require tbachert/sync
Usage
Example
$example = new Example(); await([ async($example->increment(...), 5), async($example->increment(...), 4), async(fn() => var_dump($example->get())), ]); var_dump($example->get()); // int(0) // int(4) $example = new ExampleSynchronized(); await([ async($example->increment(...), 5), async($example->increment(...), 4), async(fn() => var_dump($example->get())), ]); var_dump($example->get()); // int(9) // int(9) class Example { private int $value = 0; public function increment(int $count): void { $current = $this->value; delay(0); $this->value = $current + $count; } public function get(): int { return $this->value; } } class ExampleSynchronized { private Example $example; private ReadWriteLock $lock; public function __construct() { $this->example = new Example(); $this->lock = new LocalReadWriteLock(); } public function increment(int $count): void { synchronized( $this->lock->writeLock(), $this->example->increment(...), [$count], ); } public function get(): int { return synchronized( $this->lock->readLock(), $this->example->get(...), ); } }
统计信息
- 总下载量: 38
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2022-11-17