Aurora. Uix. Counter
(Aurora UIX v0.1.4-rc.0)
Copy Markdown
Counter utility for generating unique component identifiers in Aurora UIX.
Provides functions to start, increment, peek, and reset named or unnamed counters.
Key Constraints
- Counter names must be unique if using named counters.
- All operations are process-safe via :atomics.
- Not intended for general-purpose counting outside UIX internals.
Key Features
- Increment and retrieve the next value atomically
- Peek at the current value without incrementing
- Reset counters to a specific value
Example
# Start a named counter
Aurora.Uix.Counter.start_counter(:my_counter, 100)
# Get the next value
Aurora.Uix.Counter.next_count(:my_counter)
# => 101
# Peek at the current value
Aurora.Uix.Counter.peek_count(:my_counter)
# => 101
# Reset the counter
Aurora.Uix.Counter.reset_count(:my_counter, 50)
# => :my_counter
Summary
Functions
Increments and returns the next value for a counter.
Returns the current counter value without incrementing.
Resets a counter to a specified value.
Initializes a new counter for generating unique component identifiers.
Functions
@spec next_count( atom() | :atomics.atomics_ref() | {atom(), term()} | {:via, atom(), term()} ) :: integer()
Increments and returns the next value for a counter.
Parameters
name(atom() | :atomics.atomics_ref() | {atom(), term()} | {:via, atom(), term()}) - Counter reference.
Returns
integer() - Next counter value.
Examples
Aurora.Uix.Counter.next_count(:my_counter)
# => 11
Aurora.Uix.Counter.next_count(self())
# => 1
Returns the current counter value without incrementing.
Parameters
name(atom() | binary()) - Counter reference.
Returns
integer() - Current counter value.
Examples
Aurora.Uix.Counter.peek_count(:my_counter)
# => 11
Aurora.Uix.Counter.peek_count(self())
# => 1
@spec reset_count(atom() | binary() | :atomics.atomics_ref(), integer()) :: atom() | binary() | :atomics.atomics_ref()
Resets a counter to a specified value.
Parameters
name(atom() | binary() | :atomics.atomics_ref()) - Counter reference.initial(integer()) - Value to reset the counter to.
Returns
atom() | binary() | :atomics.atomics_ref() - Counter reference (name or PID).
Examples
Aurora.Uix.Counter.reset_count(:my_counter, 0)
# => :my_counter
Aurora.Uix.Counter.reset_count(self(), 42)
# => self()
@spec start_counter(atom() | binary() | :atomics.atomics_ref() | nil, integer()) :: atom() | binary() | :atomics.atomics_ref()
Initializes a new counter for generating unique component identifiers.
Parameters
name(atom() | binary() | nil) - Counter identifier. Ifnil, an unnamed agent is started and its PID is returned.initial(integer()) - Starting value for the counter.
Returns
atom() | binary() | :atomics.atomics_ref() - Counter reference (name or PID).
Examples
Aurora.Uix.Counter.start_counter(:my_counter, 10)
# => :my_counter
Aurora.Uix.Counter.start_counter(nil, 5)
# => #PID<...>