rasa/counter
Atomic counters for generating sequential integer values. Counters are
used by rasa/queue to index entries but can also be used on their own.
Use atomic for a simple incrementing counter, monotonic for
nanosecond-precision monotonic time values, or new to supply a custom
function.
Types
The time unit for a monotonic counter. This is passed directly to
Erlang’s monotonic_time.
pub type TimeUnit {
Second
Millisecond
Microsecond
Nanosecond
Native
}
Constructors
-
SecondMonotonic time in seconds.
-
MillisecondMonotonic time in milliseconds.
-
MicrosecondMonotonic time in microseconds.
-
NanosecondMonotonic time in nanoseconds.
-
NativeNative time unit used by the erlang runtime system.
Values
pub fn atomic() -> Counter
Returns an atomic Counter that increases by 1 every time it’s passed to
next.
pub fn monotonic(unit: TimeUnit) -> Counter
Returns a Counter tied to erlang’s monotonic_time. This counter
will provide monotonically increasing time values, but consecutive calls
to next may return the same result.
pub fn new(handle_next: fn() -> Result(Int, Nil)) -> Counter
Creates a Counter from a custom function. The function is called each
time the counter is passed to counter.next.