Skip to content

Commit 117b8df

Browse files
Add init_producer/4
1 parent 142da70 commit 117b8df

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lib/gen_stage.ex

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,10 +1867,10 @@ defmodule GenStage do
18671867
def init({mod, args}) do
18681868
case mod.init(args) do
18691869
{:producer, state} ->
1870-
init_producer(mod, [], state, nil)
1870+
init_producer(mod, [], state)
18711871

18721872
{:producer, state, opts} when is_list(opts) ->
1873-
init_producer(mod, opts, state, nil)
1873+
init_producer(mod, opts, state)
18741874

18751875
{:producer, state, opts, additional_info} when is_list(opts) ->
18761876
init_producer(mod, opts, state, additional_info)
@@ -1904,7 +1904,7 @@ defmodule GenStage do
19041904
end
19051905
end
19061906

1907-
defp init_producer(mod, opts, state, additional_info) do
1907+
defp init_producer(mod, opts, state) do
19081908
with {:ok, dispatcher_mod, dispatcher_state, opts} <- init_dispatcher(opts),
19091909
{:ok, buffer_size, opts} <-
19101910
Utils.validate_integer(opts, :buffer_size, 10000, 0, :infinity, true),
@@ -1923,13 +1923,18 @@ defmodule GenStage do
19231923
dispatcher_mod: dispatcher_mod,
19241924
dispatcher_state: dispatcher_state
19251925
}
1926-
1927-
if additional_info, do: {:ok, stage, additional_info}, else: {:ok, stage}
1926+
{:ok, stage}
19281927
else
19291928
{:error, message} -> {:stop, {:bad_opts, message}}
19301929
end
19311930
end
19321931

1932+
defp init_producer(mod, opts, state, additional_info) do
1933+
with {:ok, stage} <- init_producer(mod, opts, state) do
1934+
{:ok, stage, additional_info}
1935+
end
1936+
end
1937+
19331938
defp init_dispatcher(opts) do
19341939
case Keyword.pop(opts, :dispatcher, GenStage.DemandDispatcher) do
19351940
{dispatcher, opts} when is_atom(dispatcher) ->

0 commit comments

Comments
 (0)