Various improvements

This commit is contained in:
Daniil Gentili 2020-10-06 17:33:18 +02:00
parent b22a193014
commit 1d16cf807b
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
3 changed files with 24 additions and 4 deletions

View File

@ -258,7 +258,7 @@ class API extends InternalDoc
}
$this->API->unreference();
}
if (isset($this->wrapper) && !Magic::$signaled) {
if (isset($this->wrapper) && (!Magic::$signaled || $this->gettingApiId)) {
$this->logger->logger('Prompting final serialization...');
Tools::wait($this->wrapper->serialize());
$this->logger->logger('Done final serialization!');

View File

@ -24,6 +24,10 @@ namespace danog\MadelineProto;
*/
abstract class EventHandler extends InternalDoc
{
/**
* Whether the event handler was started.
*/
private bool $startedInternal = false;
/**
* Internal constructor.
*
@ -41,6 +45,23 @@ abstract class EventHandler extends InternalDoc
$this->{$namespace} = $this->exportNamespace($namespace);
}
}
/**
* Start method handler.
*
* @internal
*
* @return \Generator
*/
public function startInternal(): \Generator
{
if ($this->startedInternal) {
return;
}
if (\method_exists($this, 'onStart')) {
yield $this->onStart();
}
$this->startedInternal = true;
}
/**
* Get peers where to send error reports.
*

View File

@ -79,6 +79,7 @@ trait Events
}
$this->initEventHandler($eventHandler);
$this->eventHandlerMethods = [];
$this->loop_callback = null;
foreach (\get_class_methods($this->event_handler) as $method) {
if ($method === 'onLoop') {
$this->loop_callback = [$this->event_handler_instance, 'onLoop'];
@ -96,9 +97,7 @@ trait Events
}
}
yield from $this->setReportPeers($this->event_handler_instance->getReportPeers());
if (\method_exists($this->event_handler_instance, 'onStart')) {
Tools::callFork($this->event_handler_instance->onStart());
}
Tools::callFork($this->event_handler_instance->startInternal());
$this->updateHandler = [$this, 'eventUpdateHandler'];
if ($this->inited()) {
$this->startUpdateSystem();