eee
This commit is contained in:
+15
-4
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Kiri\Server\Task;
|
namespace Kiri\Server\Task;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use Kiri\Server\ServerInterface;
|
use Kiri\Server\ServerInterface;
|
||||||
|
|
||||||
class TaskExecute implements TaskInterface
|
class TaskExecute implements TaskInterface
|
||||||
@@ -9,14 +10,19 @@ class TaskExecute implements TaskInterface
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param OnTaskInterface $handler
|
* @param string $handler
|
||||||
* @param mixed $data
|
* @param mixed $data
|
||||||
* @param int $dstWorkerId
|
* @param int $dstWorkerId
|
||||||
* @param callable|null $finishFinishCallback
|
* @param callable|null $finishFinishCallback
|
||||||
* @return void
|
* @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 = \Kiri::getDi()->get(ServerInterface::class);
|
||||||
|
|
||||||
$server->task([$handler, $data], $dstWorkerId, $finishFinishCallback);
|
$server->task([$handler, $data], $dstWorkerId, $finishFinishCallback);
|
||||||
@@ -24,14 +30,19 @@ class TaskExecute implements TaskInterface
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param OnTaskInterface $handler
|
* @param string $handler
|
||||||
* @param mixed $data
|
* @param mixed $data
|
||||||
* @param float $timeout
|
* @param float $timeout
|
||||||
* @param int $dstWorkerId
|
* @param int $dstWorkerId
|
||||||
* @return mixed
|
* @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);
|
$server = \Kiri::getDi()->get(ServerInterface::class);
|
||||||
|
|
||||||
return $server->taskwait([$handler, $data], $timeout, $dstWorkerId);
|
return $server->taskwait([$handler, $data], $timeout, $dstWorkerId);
|
||||||
|
|||||||
@@ -7,23 +7,23 @@ interface TaskInterface
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param OnTaskInterface $handler
|
* @param string $handler
|
||||||
* @param mixed $data
|
* @param mixed $data
|
||||||
* @param int $dstWorkerId
|
* @param int $dstWorkerId
|
||||||
* @param callable|null $finishFinishCallback
|
* @param callable|null $finishFinishCallback
|
||||||
* @return void
|
* @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 mixed $data
|
||||||
* @param float $timeout
|
* @param float $timeout
|
||||||
* @param int $dstWorkerId
|
* @param int $dstWorkerId
|
||||||
* @return mixed
|
* @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;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user