PHPDaemon\Core\CallbackWrapper::__invoke PHP Method

__invoke() public method

Invokes the callback
public __invoke ( $args ) : mixed
$args Arguments
return mixed
    public function __invoke(...$args)
    {
        if ($this->timer !== null) {
            Timer::remove($this->timer);
            $this->timer = null;
        }
        if ($this->cb === null) {
            return null;
        }
        if ($this->context === null || Daemon::$context !== null) {
            try {
                $cb = $this->cb;
                return $cb(...$args);
            } catch (\Exception $e) {
                Daemon::uncaughtExceptionHandler($e);
            }
            return;
        }
        $this->context->onWakeup();
        try {
            $cb = $this->cb;
            $result = $cb(...$args);
            $this->context->onSleep();
            return $result;
        } catch (\Exception $e) {
            Daemon::uncaughtExceptionHandler($e);
            $this->context->onSleep();
        }
    }