承接 tbachert/sync 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2022-11-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固