Skip to main content

README.md

# AtomicFlags

An Elixir library which introduces enums and integer flags on
top of `:atomics` erlang module with minimal runtime overhead possible.

## Features

* Set, get, swap, cycle values.
* Values can be any term.
* Optimized for zero runtime dispatch when arguments are provided as literals.

## Example

```elixir
defmodule FeatureFlags do
  use AtomicFlags, schema: [
    feature_enabled: [false, true]
  ]
end

iex> require FeatureFlags
iex> flags = FeatureFlags.new()
iex> FeatureFlags.set(flags, :feature_enabled, true)
iex> FeatureFlags.get(flags, :feature_enabled)
true
```

Or with `global: true`

```elixir
defmodule GlobalFeatureFlags do
  use AtomicFlags,
    global: true,
    schema: [
      feature: [:disabled, :for_preview, :enabled]
    ]
end

iex> require GlobalFeatureFlags
iex> GlobalFeatureFlags.new_global()
iex> GlobalFeatureFlags.set(:feature, :for_preview)
iex> GlobalFeatureFlags.get(:feature)
:for_preview
```

## Installation

```elixir
def deps do
  [
    {:atomic_flags, "~> 1.0"}
  ]
end
```