       {:DOWN, ^mon, _, _, :shutdown} when type in [:shutdown, :timeout_kill] ->
         Process.demonitor(ref, [:flush])
         flush_reply(ref)
+
       {:DOWN, ^mon, _, _, :killed} when type == :brutal_kill ->
         Process.demonitor(ref, [:flush])
         flush_reply(ref)
+
       {:DOWN, ^mon, _, proc, :noproc} ->
         reason = flush_noproc(ref, proc, type)
         flush_reply(ref) || reason
+
       {:DOWN, ^mon, _, proc, reason} ->
         Process.demonitor(ref, [:flush])
         flush_reply(ref) || {:down, proc, reason}

  ## Helpers

  defp reason(:noconnection, proc), do: {:nodedown, monitor_node(proc)}
  defp reason(reason, _),           do: reason

  defp monitor_node(pid) when is_pid(pid), do: node(pid)
  defp monitor_node({_, node}),            do: node

  # spawn a process to ensure task gets exit signal if process dies from exit signal
  # between unlink and exit.
  defp exit(task, reason) do
    caller = self()
    ref = make_ref()
    enforcer = spawn(fn() -> enforce_exit(task, reason, caller, ref) end)
    Process.unlink(task)
    Process.exit(task, reason)
    send(enforcer, {:done, ref})

  `{:exit, :noproc}` as the result or exit reason can not be determined.
  """
  @spec shutdown(t, timeout | :brutal_kill) :: {:ok, term} | {:exit, term} | nil
  def shutdown(task, shutdown \\ 5000)

  def shutdown(%Task{pid: nil} = task, _) do
    raise ArgumentError, "task #{inspect(task)} does not have an associated task process"
  end

  def shutdown(%Task{owner: owner} = task, _) when owner != self() do
