qqq
This commit is contained in:
+36
-16
@@ -24,6 +24,16 @@ class Task implements TaskInterface
|
|||||||
public ServerInterface $server;
|
public ServerInterface $server;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
* @throws ReflectionException
|
||||||
|
*/
|
||||||
|
public function init(): void
|
||||||
|
{
|
||||||
|
$this->server = Kiri::getDi()->get(ServerInterface::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Server $server
|
* @param Server $server
|
||||||
* @return void
|
* @return void
|
||||||
@@ -76,26 +86,36 @@ class Task implements TaskInterface
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array|string|object $handler
|
* @param mixed $data
|
||||||
* @param int|null $workerId
|
* @param float $timeout
|
||||||
* @return void
|
* @param int $dstWorkerId
|
||||||
* @throws ReflectionException
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function dispatch(array|string|object $handler, ?int $workerId = null): void
|
public function taskWait(mixed $data, float $timeout = 0.5, int $dstWorkerId = -1): mixed
|
||||||
{
|
{
|
||||||
if (is_null($workerId)) {
|
return $this->server->taskwait($data, $timeout, $dstWorkerId);
|
||||||
$workerId = rand(0, $this->server->setting[Constant::OPTION_TASK_WORKER_NUM] - 1);
|
|
||||||
}
|
}
|
||||||
if (is_string($handler)) {
|
|
||||||
$this->server->task(serialize([di($handler), 'handle']), $workerId);
|
|
||||||
} else if (is_array($handler)) {
|
/**
|
||||||
if (is_string($handler[0])) {
|
* @param array $tasks
|
||||||
$handler[0] = di($handler[0]);
|
* @param float $timeout
|
||||||
}
|
* @return false|array
|
||||||
$this->server->task(serialize($handler), $workerId);
|
*/
|
||||||
} else {
|
public function taskCo(array $tasks, float $timeout = 0.5): false|array
|
||||||
$this->server->task(serialize([$handler, 'handle']), $workerId);
|
{
|
||||||
|
return $this->server->taskCo($tasks, $timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $tasks
|
||||||
|
* @param float $timeout
|
||||||
|
* @return false|array
|
||||||
|
*/
|
||||||
|
public function taskWaitMulti(array $tasks, float $timeout = 0.5): false|array
|
||||||
|
{
|
||||||
|
return $this->server->taskWaitMulti($tasks, $timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+18
-4
@@ -7,11 +7,25 @@ interface TaskInterface
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $handler
|
* @param array $tasks
|
||||||
* @param int|null $workerId
|
* @param float $timeout
|
||||||
* @return void
|
* @return false|array
|
||||||
*/
|
*/
|
||||||
public function dispatch(array $handler, ?int $workerId = null): void;
|
public function taskWaitMulti(array $tasks, float $timeout = 0.5): false|array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $tasks
|
||||||
|
* @param float $timeout
|
||||||
|
* @return false|array
|
||||||
|
*/
|
||||||
|
public function taskCo(array $tasks, float $timeout = 0.5): false|array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $data
|
||||||
|
* @param float $timeout
|
||||||
|
* @param int $dstWorkerId
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function taskWait(mixed $data, float $timeout = 0.5, int $dstWorkerId = -1): mixed;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user