This commit is contained in:
2023-08-17 17:04:55 +08:00
parent b26d5074fc
commit 5150b9027e
3 changed files with 56 additions and 45 deletions
+1 -3
View File
@@ -118,9 +118,7 @@ class AsyncServer implements ServerInterface
return; return;
} }
$container = Kiri::getDi(); $container = Kiri::getDi();
$task = $container->get(Task::class); $container->get(Task::class)->initTaskWorker($this->server);
$container->bind(TaskInterface::class, $task);
$task->initTaskWorker($this->server);
} }
+1 -42
View File
@@ -15,16 +15,9 @@ use Kiri\Di\Inject\Container;
/** /**
* *
*/ */
class Task implements TaskInterface class Task
{ {
/**
* @var ServerInterface
*/
#[Container(ServerInterface::class)]
public ServerInterface $server;
/** /**
* @param Server $server * @param Server $server
* @return void * @return void
@@ -76,38 +69,4 @@ class Task implements TaskInterface
} }
/**
* @param mixed $data
* @param float $timeout
* @param int $dstWorkerId
* @return mixed
*/
public function taskWait(mixed $data, float $timeout = 0.5, int $dstWorkerId = -1): mixed
{
return $this->server->taskwait($data, $timeout, $dstWorkerId);
}
/**
* @param array $tasks
* @param float $timeout
* @return false|array
*/
public function taskCo(array $tasks, float $timeout = 0.5): false|array
{
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);
}
} }
+54
View File
@@ -0,0 +1,54 @@
<?php
namespace Kiri\Server\Task;
use Kiri\Di\Inject\Container;
use Kiri\Server\ServerInterface;
class TaskExecute implements TaskInterface
{
/**
* @var ServerInterface
*/
#[Container(ServerInterface::class)]
public ServerInterface $server;
/**
* @param mixed $data
* @param float $timeout
* @param int $dstWorkerId
* @return mixed
*/
public function taskWait(mixed $data, float $timeout = 0.5, int $dstWorkerId = -1): mixed
{
return $this->server->taskwait($data, $timeout, $dstWorkerId);
}
/**
* @param array $tasks
* @param float $timeout
* @return false|array
*/
public function taskCo(array $tasks, float $timeout = 0.5): false|array
{
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);
}
}