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();
}
}