Removed signal handler altogether - what a mess

This commit is contained in:
Joop Schilder 2019-01-16 17:47:47 +01:00
parent 6a664dde4c
commit 826553a24e
1 changed files with 13 additions and 34 deletions

View File

@ -70,12 +70,18 @@ class Asynchronous
*/
$instance->isChild = true;
$instance->attachShm();
try {
$response = call_user_func_array($function, $parameters);
shm_put_var($instance->shm, $key, $response ?? Promise::RESPONSE_NONE);
if (is_resource($instance->shm))
shm_put_var($instance->shm, $key, $response ?? Promise::RESPONSE_NONE);
exit(0);
} catch (\Throwable $throwable) {
shm_put_var($instance->shm, $key, Promise::RESPONSE_ERROR);
if (is_resource($instance->shm))
shm_put_var($instance->shm, $key, Promise::RESPONSE_ERROR);
exit(1);
}
}
@ -105,14 +111,6 @@ class Asynchronous
self::getInstance()->_awaitChildren();
}
/**
* Very, very inappropriate name.
*/
public static function killChildren()
{
self::getInstance()->_killChildren();
}
/**
*
*/
@ -165,21 +163,6 @@ class Asynchronous
return $this;
}
/**
* @return $this
*/
private function _killChildren()
{
/*
* Require the children to terminate
*/
foreach ($this->children as $index => $pid)
if (!posix_kill($pid, SIGKILL))
posix_kill($pid, SIGTERM);
return $this;
}
/**
* @return $this
*/
@ -264,18 +247,14 @@ class Asynchronous
$instance->_awaitChildren();
$instance->_removeShmBlock();
});
}
public function __destruct()
{
/*
* The signal handler
* To be sure - add destructor
*/
foreach ([SIGINT, SIGTERM] as $signal)
pcntl_signal($signal, function ($signal) use (&$instance) {
if ($instance->isChild)
return;
$instance->_killChildren();
$instance->_removeShmBlock();
});
self::removeShmBlock();
}
}