Skip to content

Commit

Permalink
Merge pull request commanded#501 from yordis/typespec-1
Browse files Browse the repository at this point in the history
chore: improve typespec for router dispatch resp
  • Loading branch information
slashdotdash authored Sep 2, 2022
2 parents 21faf54 + 665869a commit dea5ed7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 32 deletions.
18 changes: 2 additions & 16 deletions lib/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,7 @@ defmodule Commanded.Application do
`Commanded.Commands.Router` and included in the application.
"""
@callback dispatch(command :: struct()) ::
:ok
| {:ok, aggregate_state :: struct()}
| {:ok, aggregate_version :: non_neg_integer()}
| {:ok, execution_result :: Commanded.Commands.ExecutionResult.t()}
| {:error, :unregistered_command}
| {:error, :consistency_timeout}
| {:error, reason :: term()}
@callback dispatch(command :: struct()) :: Commanded.Commands.Router.dispatch_resp()

@doc """
Dispatch a registered command.
Expand Down Expand Up @@ -364,14 +357,7 @@ defmodule Commanded.Application do
@callback dispatch(
command :: struct(),
timeout_or_opts :: non_neg_integer() | :infinity | Keyword.t()
) ::
:ok
| {:ok, aggregate_state :: struct()}
| {:ok, aggregate_version :: non_neg_integer()}
| {:ok, execution_result :: Commanded.Commands.ExecutionResult.t()}
| {:error, :unregistered_command}
| {:error, :consistency_timeout}
| {:error, reason :: term()}
) :: Commanded.Commands.Router.dispatch_resp()

@doc false
def dispatch(application, command, opts \\ [])
Expand Down
27 changes: 11 additions & 16 deletions lib/commanded/commands/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,15 @@ defmodule Commanded.Commands.Router do
end
end

@type dispatch_resp ::
:ok
| {:ok, aggregate_state :: struct()}
| {:ok, aggregate_version :: non_neg_integer()}
| {:ok, execution_result :: Commanded.Commands.ExecutionResult.t()}
| {:error, :unregistered_command}
| {:error, :consistency_timeout}
| {:error, reason :: term()}

@doc """
Dispatch the given command to the registered handler.
Expand All @@ -377,14 +386,7 @@ defmodule Commanded.Commands.Router do
:ok = BankRouter.dispatch(command)
"""
@callback dispatch(command :: struct()) ::
:ok
| {:ok, aggregate_state :: struct()}
| {:ok, aggregate_version :: non_neg_integer()}
| {:ok, execution_result :: Commanded.Commands.ExecutionResult.t()}
| {:error, :unregistered_command}
| {:error, :consistency_timeout}
| {:error, reason :: term()}
@callback dispatch(command :: struct()) :: dispatch_resp

@doc """
Dispatch the given command to the registered handler providing a timeout.
Expand Down Expand Up @@ -460,14 +462,7 @@ defmodule Commanded.Commands.Router do
@callback dispatch(
command :: struct(),
timeout_or_opts :: non_neg_integer() | :infinity | Keyword.t()
) ::
:ok
| {:ok, aggregate_state :: struct()}
| {:ok, aggregate_version :: non_neg_integer()}
| {:ok, execution_result :: Commanded.Commands.ExecutionResult.t()}
| {:error, :unregistered_command}
| {:error, :consistency_timeout}
| {:error, reason :: term()}
) :: dispatch_resp

defmacro __before_compile__(_env) do
quote generated: true do
Expand Down

0 comments on commit dea5ed7

Please sign in to comment.