wpjscc/reactphp-task
最新稳定版本:v1.0.1
Composer 安装命令:
composer require wpjscc/reactphp-task
包简介
README 文档
README
install
composer require wpjscc/reactphp-task
example
success
use Wpjscc\Task\Task;
Task::$processNumber = 4;
$event = Task::addTask(function ($uuid) {
Task::replayData($uuid, 'hello world');
return 'success';
});
$event->on('data', function ($data) {
echo ($data) . "\n";
});
$event->once('success', function ($data) {
echo ($data) . "\n";
});
fail
use Wpjscc\Task\Task;
Task::$processNumber = 4;
$event = Task::addTask(function ($uuid) {
Task::replayData($uuid, 'hello world');
Task::replayFail($uuid, 'task is fail');
return false;
});
$event->on('data', function ($data) {
echo ($data) . "\n";
});
$event->once('fail', function ($data) {
echo ($data) . "\n";
});
event
use Wpjscc\Task\Task;
use Evenement\EventEmitter;
use React\EventLoop\Loop;
Task::$processNumber = 4;
$event = Task::addTask(function ($uuid) {
$event = new EventEmitter();
$timer = Loop::addPeriodicTimer(1, function () use ($event, $uuid) {
$event->emit('data', ['hello world']);
});
Loop::addTimer(10, function () use ($event, $timer) {
Loop::cancelTimer($timer);
$event->emit('success', ['hello world success']);
});
return $event;
});
$event->on('data', function ($data) {
echo ($data)."\n";
});
$event->once('success', function ($data) {
echo ($data)."\n";
});
once
use Wpjscc\Task\Task;
$event = Task::addTask(function ($uuid) {
return [
'code' => 0,
'data' => [
'name' => 'once process',
]
];
}, true);
$event->on('data', function ($data) {
echo ($data) . "\n";
});
$event->once('fail', function ($data) {
echo ($data) . "\n";
});
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-12-22