stratadox/observation-queue
Composer 安装命令:
composer require stratadox/observation-queue
包简介
README 文档
README
Safeguard for observers to prevent problems in the invocation order.
Installation
Install using composer:
composer require stratadox/observation-queue
Why use this?
Use this if you have situations where observers and observables are heavily used.
Observers, by default, come with a few pretty tricky gotcha's. Reentry, for instance, may cause bugs that can get pretty difficult to find.
Example
Let's take a look at the following scenario:
We have two observables, Foo and Bar.
Observer A observes Foo, triggering Bar on update.
Observer B observes both Foo and Bar.
Foo gets triggered.
What happens here?
Since Observer A got registered to Foo before Observer B got registered,
Observer A is updated first.
Updating Observer A triggers Bar, which in turn leads to Bar updating its
subscribers.
Makes sense for far, right?
But here's the tricky part: At this point, Foo has not yet updated Observer B!
Of course, Observer B will eventually get updated by Foo. But only after
receiving the update from Bar.
The alternative
In situations where an Observer can trigger an update to an Observable, and the execution order of the relevant observers is of some importance, it may be wise to use the ObservationQueue.
The ObservationQueue is a queue of all the messages that still need to be sent to the observers. Observables add their items to the queue, and proceed to trigger the execution of the queue.
Due to this queueing layer, observer notifications are processed in the order in which the observables got triggered.
What's the price?
Although the monetary price of the software is zero, using this mechanism does introduce some shared mutable state. In order for the queue to have any effect, multiple observables need to be given access.
Basic use
Normally, updating the subscribers of an Observable would go roughly like this:
foreach ($this->subscribers as $subscriber) { $subscriber->notify($this); }
When using an observation queue, instead use:
foreach ($this->subscribers as $subscriber) { $this->queue->add($subscriber, 'notify', $this); } $this->queue->trigger();
stratadox/observation-queue 适用场景与选型建议
stratadox/observation-queue 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 01 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 stratadox/observation-queue 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 stratadox/observation-queue 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-01-28