diff options
-rw-r--r-- | lib/concurrent_limiter.ex | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/concurrent_limiter.ex b/lib/concurrent_limiter.ex index 4a367ea..f4d6fbc 100644 --- a/lib/concurrent_limiter.ex +++ b/lib/concurrent_limiter.ex @@ -105,19 +105,22 @@ defmodule ConcurrentLimiter do limiter: name }) - Process.flag(:trap_exit, true) + old_value = Process.flag(:trap_exit, true) try do fun.() after dec(ref, name) - Process.flag(:trap_exit, false) - receive do - {:EXIT, _, reason} -> - Process.exit(self(), reason) - after - 0 -> :noop + unless old_value do + Process.flag(:trap_exit, false) + + receive do + {:EXIT, _, reason} -> + Process.exit(self(), reason) + after + 0 -> :noop + end end end |