atomic-counter

Atomic Counters


License
Apache-2.0
Install
pip install atomic-counter==0.1.1

Documentation

Atomic Counter

Build Status Coverage License PyPI

Overview

atomic-counter is a rust library for generating a monotonically increasing sequence of integers. Depending on the particular configuration of the counter, the generated sequence will be produce unique numbers down to the nanosecond, regardless of memory state. E.g. if you quit the process and recreate a new counter >1ns later, your sequence is guaranteed to still be monotonically increasing (but with a gap).

Usage

from atomic_counter import Counter

c = Counter(base_in_nanos)

c.next()  # generate next number in sequence

To create e.g. a daily counter, pass in base=today in nanos. As this is a common occurrence for sequences that reset daily, a convenience function def daily() -> Counter: is provided.