Current section
Files
Jump to
Current section
Files
src/ssevents@reconnect.erl
-module(ssevents@reconnect).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/ssevents/reconnect.gleam").
-export([new/0, update/2, last_event_id/1, retry/1, last_event_id_header/1]).
-export_type([reconnect_state/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(" Reconnection metadata tracking.\n").
-opaque reconnect_state() :: {reconnect_state,
gleam@option:option(binary()),
gleam@option:option(integer())}.
-file("src/ssevents/reconnect.gleam", 10).
-spec new() -> reconnect_state().
new() ->
{reconnect_state, none, none}.
-file("src/ssevents/reconnect.gleam", 14).
-spec update(reconnect_state(), ssevents@event:item()) -> reconnect_state().
update(State, Item) ->
case Item of
{comment_item, _} ->
State;
{event_item, Ev} ->
{reconnect_state,
gleam@option:'or'(
ssevents@event:id_of(Ev),
erlang:element(2, State)
),
gleam@option:'or'(
ssevents@event:retry_of(Ev),
erlang:element(3, State)
)}
end.
-file("src/ssevents/reconnect.gleam", 25).
-spec last_event_id(reconnect_state()) -> gleam@option:option(binary()).
last_event_id(State) ->
erlang:element(2, State).
-file("src/ssevents/reconnect.gleam", 29).
-spec retry(reconnect_state()) -> gleam@option:option(integer()).
retry(State) ->
erlang:element(3, State).
-file("src/ssevents/reconnect.gleam", 33).
-spec last_event_id_header(reconnect_state()) -> gleam@option:option({binary(),
binary()}).
last_event_id_header(State) ->
case erlang:element(2, State) of
{some, Id} ->
{some, {<<"Last-Event-ID"/utf8>>, Id}};
none ->
none
end.