This commit is contained in:
Daniil Gentili 2019-06-07 18:33:06 +02:00
parent 24b92b9a71
commit 954c64127e
2 changed files with 10 additions and 5 deletions

View File

@ -173,8 +173,12 @@ class API extends APIFactory
if ($this->asyncInitPromise) {
$this->init();
}
$this->API->logger('Shutting down MadelineProto (normally or due to an exception, idk)');
$this->API->destructing = true;
if ($this->API) {
$this->API->logger('Shutting down MadelineProto (normally or due to an exception, idk)');
$this->API->destructing = true;
} else {
Logger::log('Shutting down MadelineProto (normally or due to an exception, idk)');
}
$this->destructing = true;
$this->wait($this->serialize());
//restore_error_handler();

View File

@ -20,6 +20,7 @@
namespace danog\MadelineProto;
use function Amp\Promise\wait;
use Amp\Loop;
class Magic
{
@ -130,9 +131,9 @@ class Magic
self::$can_getcwd = true;
} catch (\danog\MadelineProto\Exception $e) {
}
if (function_exists('\pcntl_async_signals')) {
pcntl_async_signals(true);
}
// Even an empty handler is enough to catch ctrl+c
Loop::onSignal(SIGINT, static function () { die(); });
Loop::onSignal(SIGTERM, static function () { die(); });
self::$inited = true;
}
}