Spear.ack
You're seeing just the function
ack
, go back to Spear module for more information.
Specs
ack( connection :: Spear.Connection.t(), subscription :: reference(), event_or_ids :: Spear.Event.t() | [String.t()] ) :: :ok
Acknowledges that an event received as part of a persistent subscription was successfully handled
Although ack/3
can accept a Spear.Event.t/0
alone, the underlying
gRPC call acknowledges a batch of event IDs.
Spear.ack(conn, subscription, events |> Enum.map(&Spear.Event.id/1))
should be preferred over
Enum.each(events, &Spear.ack(conn, subscription, Spear.Event.id(&1)))
As the acknowledgements will be batched.
This function (and nack/4
) are asynchronous casts to the connection
process.
Examples
# some stream with 3 events
stream_name = "my_stream"
group_name = "spear_iex"
settings = %Spear.PersistentSubscription.Settings{}
get_event_and_ack = fn conn, sub ->
receive do
%Spear.Event{} = event ->
:ok = Spear.ack(conn, sub, event)
event
after
3_000 -> :no_events
end
end
iex> Spear.create_persistent_subscription(conn, stream_name, group_name, settings)
:ok
iex> {:ok, sub} = Spear.connect_to_persistent_subscription(conn, self(), stream_name, group_name)
iex> get_event_and_ack.(conn, sub)
%Spear.Event{..}
iex> get_event_and_ack.(conn, sub)
%Spear.Event{..}
iex> get_event_and_ack.(conn, sub)
%Spear.Event{..}
iex> get_event_and_ack.(conn, sub)
:no_events
iex> Spear.cancel_subscription(conn, sub)
:ok