This commit is contained in:
2025-07-11 14:44:06 +08:00
parent c767a1745a
commit f533d3262b
2 changed files with 19 additions and 8 deletions
+15 -4
View File
@@ -2,6 +2,7 @@
namespace Kiri\Server\Task;
use Exception;
use Kiri\Server\ServerInterface;
class TaskExecute implements TaskInterface
@@ -9,14 +10,19 @@ class TaskExecute implements TaskInterface
/**
* @param OnTaskInterface $handler
* @param string $handler
* @param mixed $data
* @param int $dstWorkerId
* @param callable|null $finishFinishCallback
* @return void
* @throws
*/
public function task(OnTaskInterface $handler, mixed $data, int $dstWorkerId = -1, ?callable $finishFinishCallback = null): void
public function task(string $handler, mixed $data, int $dstWorkerId = -1, ?callable $finishFinishCallback = null): void
{
$array = class_implements($handler, false);
if (!in_array(OnTaskInterface::class, $array, true)) {
throw new Exception('Task is not implement OnTaskInterface');
}
$server = \Kiri::getDi()->get(ServerInterface::class);
$server->task([$handler, $data], $dstWorkerId, $finishFinishCallback);
@@ -24,14 +30,19 @@ class TaskExecute implements TaskInterface
/**
* @param OnTaskInterface $handler
* @param string $handler
* @param mixed $data
* @param float $timeout
* @param int $dstWorkerId
* @return mixed
* @throws
*/
public function taskWait(OnTaskInterface $handler, mixed $data, float $timeout = 0.5, int $dstWorkerId = -1): mixed
public function taskWait(string $handler, mixed $data, float $timeout = 0.5, int $dstWorkerId = -1): mixed
{
$array = class_implements($handler, false);
if (!in_array(OnTaskInterface::class, $array, true)) {
throw new Exception('Task is not implement OnTaskInterface');
}
$server = \Kiri::getDi()->get(ServerInterface::class);
return $server->taskwait([$handler, $data], $timeout, $dstWorkerId);