public function regenerateId($idOld, RequestApplicationInterface $app, $deleteOldSession = false)
    {
        $self = $this;
        $dataOld = [];
        $promise = $this->read($idOld)->then(
            function($data) { return $data; },
            function() { return []; }
        )->then(function($data) use ($idOld, &$dataOld) {
            $dataOld = $data;
            return $this->destroy($idOld)->then(null, function() { return true; });
        })->then(
            function() use ($self, &$app) {
                return $self->createId($app);
            }
        )->then(
            function($newId) use ($self, &$dataOld, $deleteOldSession) {
                $retCallback = function() use ($newId) { return $newId; };
                $dataNew = $deleteOldSession ? [] : $dataOld;
                return $self->write($newId, $dataNew)->then($retCallback, $retCallback);
            },
            function() use ($idOld) {
                $message = sprintf('Failed to regenerate session ID for session "%s"', $idOld);
                throw new SessionException($message);
            }
        );
        return $promise;
    }