eee
This commit is contained in:
+15
-4
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user