Logout user programmatically without redirect
The logout controller (UserController::logout()) does this in a separate step.

  public function logout() {
    user_logout();
    return $this-&gt;redirect('&lt;front&gt;');
  }


You can alter the controller class for the user.logout route to replace this with custom code. 

What do you want to do instead? Building an anonymous response a redirect seems to be the most straightforward solution.