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

View File

@ -70,12 +70,18 @@ class Asynchronous
*/
$instance->isChild = true;
$instance->attachShm();
try {
$response = call_user_func_array($function, $parameters);
if (is_resource($instance->shm))
shm_put_var($instance->shm, $key, $response ?? Promise::RESPONSE_NONE);
exit(0);
} catch (\Throwable $throwable) {
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();
}
}