Renamed events in GroupManager

This commit is contained in:
2024-02-22 02:01:12 +01:00
parent 3abdced846
commit 054e052da7
3 changed files with 33 additions and 5 deletions

View File

@ -13,11 +13,11 @@ class GroupManager implements EventEmitterInterface
/**
* @var string emitted when a new group is created
*/
const EVENT_CREATED = 'created';
const EVENT_CREATE = 'create';
/**
* @var string emitted after the last member leaves, when the group is destroyed
*/
const EVENT_DESTROYED = 'destroyed';
const EVENT_DESTROY = 'destroy';
/** @var array<string,ConnectionGroup> */
private array $groups = [];
@ -31,13 +31,13 @@ class GroupManager implements EventEmitterInterface
$group->on(ConnectionGroup::EVENT_LEAVE, function () use ($group) {
Loop::futureTick(function () use ($group) {
if (count($group) === 0) {
$this->emit(self::EVENT_DESTROYED, [ $group ]);
$this->emit(self::EVENT_DESTROY, [ $group ]);
$group->removeAllListeners();
unset($this->groups[$group->getName()]);
}
});
});
$this->emit(self::EVENT_CREATED, [ $group ]);
$this->emit(self::EVENT_CREATE, [ $group ]);
} else {
$group = $this->groups[$name];
}