diff options
author | Tony Garnock-Jones <tonyg@lshift.net> | 2008-12-09 17:52:10 +0000 |
---|---|---|
committer | Tony Garnock-Jones <tonyg@lshift.net> | 2008-12-09 17:52:10 +0000 |
commit | 0de13ab0f1da5dec85b691a570218e0cc72f6cef (patch) | |
tree | 37fc91be7259ffd5599773865fccefe85e37c579 /src/rabbit_misc.erl | |
parent | 68afd00b8bc9e4b8d29243a5ed47b9b1ab3962bc (diff) | |
parent | 84030fb5c52543c9fa700c46cb18f7d6bce5f2a2 (diff) | |
download | rabbitmq-server-0de13ab0f1da5dec85b691a570218e0cc72f6cef.tar.gz |
merged default into bug18381bug18381
Diffstat (limited to 'src/rabbit_misc.erl')
-rw-r--r-- | src/rabbit_misc.erl | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index d0d8fe8b..973e163b 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -40,7 +40,7 @@ -export([dirty_read/1]). -export([r/3, r/2, rs/1]). -export([enable_cover/0, report_cover/0]). --export([throw_on_error/2, with_exit_handler/2]). +-export([throw_on_error/2, with_exit_handler/2, filter_exit_map/2]). -export([with_user/2, with_vhost/2, with_user_and_vhost/3]). -export([execute_mnesia_transaction/1]). -export([ensure_ok/2]). @@ -87,6 +87,7 @@ -spec(throw_on_error/2 :: (atom(), thunk({error, any()} | {ok, A} | A)) -> A). -spec(with_exit_handler/2 :: (thunk(A), thunk(A)) -> A). +-spec(filter_exit_map/2 :: (fun ((A) -> B), [A]) -> [B]). -spec(with_user/2 :: (username(), thunk(A)) -> A). -spec(with_vhost/2 :: (vhost(), thunk(A)) -> A). -spec(with_user_and_vhost/3 :: (username(), vhost(), thunk(A)) -> A). @@ -224,6 +225,13 @@ with_exit_handler(Handler, Thunk) -> Handler() end. +filter_exit_map(F, L) -> + Ref = make_ref(), + lists:filter(fun (R) -> R =/= Ref end, + [with_exit_handler( + fun () -> Ref end, + fun () -> F(I) end) || I <- L]). + with_user(Username, Thunk) -> fun () -> case mnesia:read({user, Username}) of |