public function setConnection($connection = null)
    {
        if ($connection instanceof TransactionInterface) {
            $connection = $connection->getConnection();
        }
        $this->connection = $connection;
        if ($connection instanceof EventEmitterWildcardInterface) {
            //Remove connection instance on close
            $this->connection->once(ConnectionInterface::EVENT_CLOSE, function() use ($connection) {
                if ($this->connection === $connection) {
                    $this->connection = null;
                }
            });
        }
        return $this;
    }