Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract subscribe_to_stream function #13

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions lib/extreme.ex
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,28 @@ defmodule Commanded.EventStore.Adapters.Extreme do
end
end

@spec subscribe_to_all_streams(String.t(), pid, Commanded.EventStore.start_from()) ::
@spec subscribe_to_stream(
String.t(),
String.t(),
pid(),
Commanded.EventStore.start_from(),
Keyword.t()
) ::
{:ok, subscription :: pid}
| {:error, :subscription_already_exists}
| {:error, term}
def subscribe_to_all_streams(subscription_name, subscriber, start_from \\ :origin)

def subscribe_to_all_streams(subscription_name, subscriber, start_from) do
stream = "$ce-" <> @stream_prefix
def subscribe_to_stream(
stream_name,
subscription_name,
subscriber,
start_from \\ :origin,
opts \\ [stream_prefix: "$ce-" <> @stream_prefix]
)

def subscribe_to_stream(stream_name, subscription_name, subscriber, start_from, opts) do
case SubscriptionsSupervisor.start_subscription(
stream,
Keyword.get(opts, :stream_prefix, "") <> stream_name,
subscription_name,
subscriber,
start_from
Expand All @@ -95,6 +106,16 @@ defmodule Commanded.EventStore.Adapters.Extreme do
end
end

@spec subscribe_to_all_streams(String.t(), pid, Commanded.EventStore.start_from()) ::
{:ok, subscription :: pid}
| {:error, :subscription_already_exists}
| {:error, term}
def subscribe_to_all_streams(subscription_name, subscriber, start_from \\ :origin)

def subscribe_to_all_streams(subscription_name, subscriber, start_from) do
subscribe_to_stream("", subscription_name, subscriber, start_from)
end

@spec ack_event(pid, RecordedEvent.t()) :: :ok
def ack_event(subscription, %RecordedEvent{event_number: event_number}) do
Subscription.ack(subscription, event_number)
Expand Down