justblackbird/amphp-priority-emitter
Composer 安装命令:
composer require justblackbird/amphp-priority-emitter
包简介
In-memory implementation of async emitter with prioritized messages
README 文档
README
In-memory implementation of async emitter with prioritized messages
Why
Implementation of AMP Emitter is backed by a queue. It covers many cases but sometimes a priority queue is needed.
For example, you're building a bot for a social network or a messenger. Assume that the bot can react for users' commands and broadcast information to all its subscribers. These two types of messages have different priorities. Commands' responses must be sent as soon as possible to keep UX responsive but broadcasting messages can wait for a while.
You can build the app around a message bus. There is some code that pushes messages to the bus, and some code that pull them out and transfer to social network API.
You cannot use Emitter shipped with AMP because in such case broadcasting messages will block command ones because there is no way to set priority with AMP Emitter.
This library adds and Emitter with API similar to AMP Emitter but with priority support.
Installation
composer require justblackbird/amphp-priority-emitter
Usage
use Amp\Loop; use JustBlackBird\AmpPriorityEmitter\Emitter; // The following example will output: // - important message // - message one // - message two Loop::run(static function() { $emitter = new Emitter(); $emitter->emit('message one', 0); $emitter->emit('message two', 0); $emitter->emit('important message', 5); $emitter->complete(); $iterator = $emitter->iterate(); while(yield $iterator->advance()) { echo "- " . $iterator->getCurrent() . "\n"; } });
License
MIT (c) Dmitry Simushev
The implementation is based on AMP Emitter.
统计信息
- 总下载量: 9
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-07-25