defused v0.6.0 Defused View Source

Provides a defused/3 macro similar to Kernel#def/2 but that wraps all calls to the provided function body in a call to the specified fuse that will check and blow the fuse as needed.

Examples

use Defused
defused :fuse_name, test(arg) do
  case :rand.uniform() < 0.5 do
    true -> {:ok, arg}
    _ -> {:error, :boom}
  end
end

Link to this section Summary

Functions

Defines a fused function with the given fuse name, function name and body

Runs the provided do block only if the fuse haven’t been blown

Link to this section Functions

Link to this macro defused(fuse, call, list) View Source (macro)

Defines a fused function with the given fuse name, function name and body.

Examples

defmodule Foo do
  defused :fuse, bar, do: :ok
end

Foo.bar #=> :ok

Returns

A defused function must return either :ok or {:ok, _}, otherwise the fuse will melt, and eventually blow.

When the fuse is blown, the function will return {:error, :unavailable}

Link to this macro fused(fuse, list) View Source (macro)

Runs the provided do block only if the fuse haven’t been blown.

Examples

def func() do

fused :fuse, do
  :ok
end

end