Exop v1.1.1 Exop.Chain View Source

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).

Link to this section Summary

Link to this section Functions

Link to this macro operation(operation, opts \\ []) View Source (macro)