Skip to content

hissssst/atomic_flags

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

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

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

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

About

No description, website, or topics provided.

Resources

License

Stars

2 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors