public function execute($command, callable $next)
    {
        try {
            $result = $next($command);
        } catch (\Exception $exception) {
            $this->eventRecorder->eraseEvents();

            throw $exception;
        }

        $recordedEvents = $this->eventRecorder->releaseEvents();

        foreach ($recordedEvents as $event) {
            $this->eventDispatcher->dispatch($event);
        }

        return $result;
    }