View Source Exop.Chain (Exop v1.4.5)

Provides macros to organize a number of Exop.Operation modules into an invocation chain.

Example

defmodule CreateUser do
  use Exop.Chain

  alias Operations.{User, Backoffice, Notifications}

  operation User.Create
  operation Backoffice.SaveStats
  operation Notifications.SendEmail
end

# CreateUser.run(name: "User Name", age: 37, gender: "m")

Exop.Chain defines run/1 function that takes keyword() or map() of params. Those params will be passed into the first operation in the chain. Bear in mind that each of chained operations (except the first one) awaits a returned result of a previous operation as incoming params.

So in the example above CreateUser.run(name: "User Name", age: 37, gender: "m") will invoke the chain by passing [name: "User Name", age: 37, gender: "m"] params to the first User.Create operation. The result of User.Create operation will be passed to Backoffice.SaveStats operation as its params and so on.

Once any of operations in the chain returns non-ok-tuple result (error result, interruption, auth error etc.) the chain execution interrupts and error result returned (as the chain (CreateUser) result).

Summary

Functions

Defines one of a chain's operation.

Defines one of a chain's operation.

Functions

Link to this macro

operation(operation, opts \\ [])

View Source (macro)
@spec operation(
  module(),
  keyword()
) :: any()

Defines one of a chain's operation.

Link to this macro

step(operation, opts \\ [])

View Source (macro)
@spec step(
  module(),
  keyword()
) :: any()

Defines one of a chain's operation.