diff --git a/Task/TaskExecute.php b/Task/TaskExecute.php index f20e904..232c4a7 100644 --- a/Task/TaskExecute.php +++ b/Task/TaskExecute.php @@ -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); diff --git a/Task/TaskInterface.php b/Task/TaskInterface.php index 4c35149..a3950d0 100644 --- a/Task/TaskInterface.php +++ b/Task/TaskInterface.php @@ -7,23 +7,23 @@ interface TaskInterface /** - * @param OnTaskInterface $handler + * @param string $handler * @param mixed $data * @param int $dstWorkerId * @param callable|null $finishFinishCallback * @return void */ - 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; /** - * @param OnTaskInterface $handler + * @param string $handler * @param mixed $data * @param float $timeout * @param int $dstWorkerId * @return mixed */ - 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; /**