wpjscc / reactphp-task
v1.0.1
2023-12-23 01:31 UTC
Requires
- laravel/serializable-closure: ^1.3
- react/child-process: ^0.7@dev
- rybakit/msgpack: ^0.9.1
This package is auto-updated.
Last update: 2024-12-23 03:40:22 UTC
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";
});