Files
kiri-core/kiri-engine/Async.php
T

45 lines
712 B
PHP
Raw Normal View History

2021-01-04 18:21:37 +08:00
<?php
2021-08-11 01:04:57 +08:00
namespace Kiri;
2021-01-04 18:21:37 +08:00
use Exception;
2021-08-11 01:04:57 +08:00
use Kiri\Abstracts\Component;
2021-08-13 14:58:58 +08:00
use Server\ServerManager;
2021-12-01 15:16:08 +08:00
use Server\Tasker\AsyncTaskExecute;
2021-01-04 18:21:37 +08:00
/**
* Class Async
2021-08-11 01:04:57 +08:00
* @package Kiri
2021-01-04 18:21:37 +08:00
*/
class Async extends Component
{
2021-05-07 17:06:10 +08:00
private static array $_absences = [];
2021-04-24 20:17:55 +08:00
2021-08-13 15:11:58 +08:00
/**
* @param string $name
2021-08-13 15:22:49 +08:00
* @param string $handler
2021-08-13 15:11:58 +08:00
*/
2021-08-13 15:22:49 +08:00
public function addAsync(string $name, string $handler)
2021-04-24 20:17:55 +08:00
{
2021-08-13 15:22:49 +08:00
static::$_absences[$name] = $handler;
2021-04-24 20:17:55 +08:00
}
/**
* @param string $name
* @param array $params
* @throws Exception
*/
public function dispatch(string $name, array $params = [])
{
2021-12-01 15:16:08 +08:00
$context = di(AsyncTaskExecute::class);
$context->execute(static::$_absences[$name], $params);
2021-04-24 20:17:55 +08:00
}
2021-01-04 18:21:37 +08:00
}