protected function addPendingEvent($connection, $event, $payload)
    {
        $connectionId = $connection->getName();
        $transactionLevel = $this->transactionLevel;

        $eventData = [
            'event' => $event,
            'payload' => is_object($payload) ? clone $payload : $payload,
        ];
        $transactionLevelEvents = &$this->pendingEvents[$connectionId][$transactionLevel];
        $transactionLevelEvents[count($transactionLevelEvents) - 1][] = $eventData;
    }