Skip to content

Commit

Permalink
fix: improve iterator to not exit when opening fails
Browse files Browse the repository at this point in the history
  • Loading branch information
tlux committed Mar 28, 2024
1 parent 1481492 commit 837ea2b
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions lib/graphql_ws_client/iterator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ defmodule GraphQLWSClient.Iterator do
|> Opts.new()
|> Opts.validate!()

{:ok, iterator} = start_link(opts)
iterator
case start_link(opts) do
{:ok, iterator} -> iterator
{:error, error} -> raise error
end
end

@spec close(iterator) :: :ok
Expand All @@ -56,18 +58,21 @@ defmodule GraphQLWSClient.Iterator do

@impl true
def init(%Opts{} = opts) do
monitor_ref = Process.monitor(opts.client)

subscription_id =
GraphQLWSClient.subscribe!(opts.client, opts.query, opts.variables)

{:ok,
%State{
buffer_size: opts.buffer_size,
client: opts.client,
monitor_ref: monitor_ref,
subscription_id: subscription_id
}}
case GraphQLWSClient.subscribe(opts.client, opts.query, opts.variables) do
{:ok, subscription_id} ->
monitor_ref = Process.monitor(opts.client)

{:ok,
%State{
buffer_size: opts.buffer_size,
client: opts.client,
monitor_ref: monitor_ref,
subscription_id: subscription_id
}}

{:error, error} ->
{:stop, error}
end
end

@impl true
Expand Down

0 comments on commit 837ea2b

Please sign in to comment.