Skip to content

Commit

Permalink
Start IPC server immediately
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Aug 23, 2024
1 parent 7629e33 commit 0eb361c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs
38 changes: 24 additions & 14 deletions src/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ final class API extends AbstractAPI
*
* @var string
*/
public const RELEASE = '8.2.3';
public const RELEASE = '8.2.4';
/**
* We're not logged in.
*
Expand Down Expand Up @@ -220,6 +220,11 @@ public function __construct(string $session, ?SettingsAbstract $settings = null)
$this->wrapper->logger('Prompting initial serialization...');
$this->wrapper->serialize();
$this->wrapper->logger('Done initial serialization!');
$this->destruct();
if (!$this->connectToMadelineProto($settings)) {
throw new Exception("Could not start IPC server!");
}

$this->wrapper->logger(Lang::$current_lang['madelineproto_ready'], Logger::NOTICE);
}

Expand Down Expand Up @@ -366,6 +371,23 @@ public static function finalize(): void
await(self::$destructors);
}
}

private function destruct(int|null $id = null): void
{
$this->wrapper->logger('Shutting down MadelineProto ('.static::class.')');
$this->wrapper->getAPI()?->unreference();
if (isset($this->wrapper)) {
$this->wrapper->logger('Prompting final serialization...');
$this->wrapper->serialize();
$this->wrapper->logger('Done final serialization!');
}
if ($this->unlock) {
($this->unlock)();
}
if ($id !== null) {
unset(self::$destructors[$id]);
}
}
/**
* Destruct function.
*
Expand All @@ -374,19 +396,7 @@ public static function finalize(): void
public function __destruct()
{
$id = \count(self::$destructors);
self::$destructors[$id] = async(function () use ($id): void {
$this->wrapper->logger('Shutting down MadelineProto ('.static::class.')');
$this->wrapper->getAPI()?->unreference();
if (isset($this->wrapper)) {
$this->wrapper->logger('Prompting final serialization...');
$this->wrapper->serialize();
$this->wrapper->logger('Done final serialization!');
}
if ($this->unlock) {
($this->unlock)();
}
unset(self::$destructors[$id]);
});
self::$destructors[$id] = async($this->destruct(...), $id);
}

/**
Expand Down

0 comments on commit 0eb361c

Please sign in to comment.