Sharing and Reusing Elixir Callback Functions between Modules
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
config
lib
test
.gitignore
CHANGELOG.md
LICENSE
README.md
mix.exs
mix.lock

README.md

README

A module for sharing and reusing callback functions.

The most obvious use case is the callback functions of `GenServer` i.e. `handle_code/3`, `handle_cast/2` and `handle_info/2`.

Callback function sources have to be compiled together in the callback module to enable multiple implementations of the same callback to be found by pattern matching.

Although targetting `GenServer` callbacks, `Siariwyd` can be used to share any function's implementations (callback or otherwise) that must be compiled together.

`Siariwyd` enables one or more implementations of a function to be register-ed in one or more donor modules and selectively include-d into a recipient (e.g. callback) module at compilation time.

See full documentation for details.

See my blog post for some background.

Installation

Add siariwyd to your list of dependencies in mix.exs:

def deps do
  [{:siariwyd, "~> 0.2.0"}]
end

Examples

See the examples in the API documentation and also the blog post