discord/semaphore
Acerca de
Semáforo rápido basado en ETS.
Otros proyectosCrecimiento de estrellas medido
- in 24h
- +1
- in 7 days
- +1
- in 15 days
- +2
- in 1 month
- Recopilando historial
Cambios netos en períodos que se solapan, no totales diarios. Los datos no disponibles se dejan en blanco. Las estrellas indican interés, no calidad.
README.md
OriginalSemaphore
Programming in Erlang and Elixir usually allows for no locking since the VM essentially handles it for you when
communicating between processes. However, what about the situation when you have thousands of processes attempting
to interact with a single resource such as a process? Usually they will overload the process and explode the
message queue. ETS is the Swiss Army knife of the Erlang VM and can be applied to this problem. By using :ets.update_counter
and :write_concurrency we can achieve a fast low contention semaphore on ETS.
Usage
Add it to mix.exs
defp deps do
[{:semaphore, "~> 1.3"}]
end
Then just use it like a semaphore in any other language.
if Semaphore.acquire(:test, 1) do
IO.puts "acquired"
Semaphore.release(:test)
end
case Semaphore.call(:test, 1, fn -> :ok end) do
:ok ->
IO.puts "success"
{:error, :max} ->
IO.puts "too many callers"
end
License
Semaphore is released under the MIT License. Check LICENSE file for more information.
Explorar proyectos relacionados
Cargando…