handle($handler, $params); } if ($this->container->has(SwooleServerInterface::class)) { $server = $this->container->get(SwooleServerInterface::class); if ($workerId < 0 || $workerId > $server->setting['task_worker_num']) { $workerId = random_int(0, $server->setting['task_worker_num'] - 1); } $server->task(serialize($handler), $workerId); } } /** * @param $handler * @param $params * @return object * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface * @throws \ReflectionException * @throws Exception */ private function handle($handler, $params): object { if (!class_exists($handler) && $this->hashMap->has($handler)) { $handler = $this->hashMap->get($handler); } $implements = $this->container->getReflect($handler); if (!in_array(OnTaskInterface::class, $implements->getInterfaceNames())) { throw new Exception('Task must instance ' . OnTaskInterface::class); } return $implements->newInstanceArgs($params); } }