summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJordan Bracco <href@random.sh>2020-05-16 12:39:22 +0200
committerJordan Bracco <href@random.sh>2020-05-16 12:39:22 +0200
commit5bc10fff60e28514419b489102768db18db6afc1 (patch)
tree09dcf6aca0e1aa31bdd3c8d18b57dd57f056e9f9 /lib
parentFormat and prepare for release (diff)
Fix tests & add ConcurrentLimiter.delete/1
Diffstat (limited to 'lib')
-rw-r--r--lib/concurrent_limiter.ex15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/concurrent_limiter.ex b/lib/concurrent_limiter.ex
index 9555f00..a581447 100644
--- a/lib/concurrent_limiter.ex
+++ b/lib/concurrent_limiter.ex
@@ -73,9 +73,20 @@ defmodule ConcurrentLimiter do
end
end
+ @spec delete(name) :: :ok when name: atom()
+ @doc "Deletes a limiter."
+ def delete(name) do
+ if defined?(name) do
+ :persistent_term.put(name, nil)
+ end
+
+ :ok
+ end
+
@doc "Limits invocation of `fun`."
- @spec limit(atom(), function(), opts) :: {:error, :overload} | any()
- when opts: [option],
+ @spec limit(name, function(), opts) :: {:error, :overload} | any()
+ when name: atom(),
+ opts: [option],
option: {:wait, non_neg_integer()} | {:max_retries, non_neg_integer()}
def limit(name, fun, opts \\ []) do
do_limit(prefix_name(name), fun, opts, 0)