Skip to content

Commit

Permalink
Queue async groups until state is loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Dec 23, 2024
1 parent d78ef17 commit 45aec00
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions lib/ex_unit/lib/ex_unit/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -173,20 +173,13 @@ defmodule ExUnit.Server do
end

defp take_modules(%{waiting: {from, count}} = state) do
has_async_modules? = not :queue.is_empty(state.async_modules)
has_async_groups? = state.async_groups != []

cond do
not has_async_modules? and not has_async_groups? and state.loaded == :done ->
GenServer.reply(from, nil)
%{state | waiting: nil}

has_async_modules? ->
not :queue.is_empty(state.async_modules) ->
{reply, remaining_modules} = take_until(count, state.async_modules)
GenServer.reply(from, reply)
%{state | async_modules: remaining_modules, waiting: nil}

has_async_groups? ->
state.async_groups != [] and state.loaded == :done ->
{groups, remaining_groups} = Enum.split(state.async_groups, count)

{reply, groups} =
Expand All @@ -198,6 +191,10 @@ defmodule ExUnit.Server do
GenServer.reply(from, reply)
%{state | groups: groups, async_groups: remaining_groups, waiting: nil}

state.loaded == :done ->
GenServer.reply(from, nil)
%{state | waiting: nil}

true ->
state
end
Expand Down

0 comments on commit 45aec00

Please sign in to comment.