Alambic.CountDown
A simple countdown latch implementation useful for simple fan in scenarios. It is initialized with a count and clients can wait on it to be signaled when the count reaches 0, decrement the count or increment the count.
It is implemented as a GenServer.
In the unlikely case you need to start a named CountDown you can directly
use the GenServer.start/start_link
functions passing the required initial
count
as argument.
Summary
Functions
Return the current count
Create a CountDown object with count
initial count.
count
must be a positive integer
Create a CountDown with count
initial count. It is linked
to the current process
Destroy the countdown object, returning :error
to all waiters
Increase the count by one
Reset the count to a new value
Decrease the count by one. Returns true if the count reached 0, false otherwise
Wait for the count to reach 0
Types
t :: %Alambic.CountDown{id: pid}
Functions
Specs
create(integer) :: t
Create a CountDown object with count
initial count.
count
must be a positive integer.
iex> c = Alambic.CountDown.create(2)
iex> is_nil(c.id)
false
Specs
create_link(integer) :: t
Create a CountDown with count
initial count. It is linked
to the current process.
iex> c = Alambic.CountDown.create_link(2)
iex> Alambic.CountDown.destroy(c)
:ok
Specs
destroy(t) :: :ok
Destroy the countdown object, returning :error
to all waiters.
Specs
signal(t) :: true | false
Decrease the count by one. Returns true if the count reached 0, false otherwise.