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) { if ($this->asyncInitPromise) {
$this->init(); $this->init();
} }
$this->API->logger('Shutting down MadelineProto (normally or due to an exception, idk)'); if ($this->API) {
$this->API->destructing = true; $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->destructing = true;
$this->wait($this->serialize()); $this->wait($this->serialize());
//restore_error_handler(); //restore_error_handler();

View File

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