Skip to content

Commit

Permalink
fix possible memory leak from legacy ready event and optimize the logic
Browse files Browse the repository at this point in the history
  • Loading branch information
SQKo committed Sep 10, 2023
1 parent 6234b07 commit bf21b6c
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions src/Discord/Discord.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Discord
/**
* An array of loggers for voice clients.
*
* @var array Loggers.
* @var ?LoggerInterface[] Loggers.
*/
protected $voiceLoggers = [];

Expand Down Expand Up @@ -379,13 +379,6 @@ public function __construct(array $options = [])
$this->handlers->removeHandler($event);
}

$function = function () use (&$function) {
$this->emittedInit = true;
$this->removeListener('ready', $function);
};

$this->on('ready', $function);

$this->http = new Http(
'Bot '.$this->token,
$this->loop,
Expand Down Expand Up @@ -1130,17 +1123,14 @@ protected function ready()
if ($this->emittedInit) {
return false;
}
$this->emittedInit = true;

$this->logger->info('client is ready');
$this->emit('init', [$this]);

/* deprecated */
if ($this->listeners['ready']) {
if (count($this->listeners['ready'] ?? []) > 1 || count($this->onceListeners['ready'] ?? []) > 1) {
$this->logger->info('The \'ready\' event is deprecated and will be removed in a future version of DiscordPHP. Please use \'init\' instead.');
}

$this->emit('ready', [$this]);
if (count($this->listeners('ready'))) {
$this->logger->info("The 'ready' event is deprecated and will be removed in a future version of DiscordPHP. Please use 'init' instead.");
$this->emit('ready', [$this]); // deprecated
}

foreach ($this->unparsedPackets as $parser) {
Expand Down

0 comments on commit bf21b6c

Please sign in to comment.