diff options
author | rinpatch <rinpatch@sdf.org> | 2020-09-05 11:29:14 +0300 |
---|---|---|
committer | rinpatch <rinpatch@sdf.org> | 2020-09-05 11:29:14 +0300 |
commit | 3fb8535251ea3a72e69f82b178c1691f31ff60dc (patch) | |
tree | e20d1144599c73ea7cd0c6410942d2246f34435b | |
parent | Merge branch 'fix/trap-exits' into 'master' (diff) |
Do not untrap exits if they were already trapped before callingfix/do-not-untrap-trapped-processes
-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 |