diff options
author | Matthew Sackman <matthew@rabbitmq.com> | 2011-01-13 15:10:02 +0000 |
---|---|---|
committer | Matthew Sackman <matthew@rabbitmq.com> | 2011-01-13 15:10:02 +0000 |
commit | 0cac631d4359aed966c307636c24781c42e923ce (patch) | |
tree | 2e1587d6a8d544f95d1cac0bd3e3896630db24a6 /src/rabbit_misc.erl | |
parent | 801ceca09c3567f181d833f32888aed52ebdf64d (diff) | |
download | rabbitmq-server-0cac631d4359aed966c307636c24781c42e923ce.tar.gz |
Some refactorings
Diffstat (limited to 'src/rabbit_misc.erl')
-rw-r--r-- | src/rabbit_misc.erl | 41 |
1 files changed, 14 insertions, 27 deletions
diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index dbc09e7f..9e8ba91b 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -49,7 +49,6 @@ -export([with_user/2, with_user_and_vhost/3]). -export([execute_mnesia_transaction/1]). -export([execute_mnesia_transaction/2]). --export([execute_mnesia_transaction/3]). -export([execute_mnesia_tx_with_tail/1]). -export([ensure_ok/2]). -export([makenode/1, nodeparts/1, cookie_hash/0, tcp_name/3]). @@ -148,8 +147,6 @@ -spec(execute_mnesia_transaction/1 :: (thunk(A)) -> A). -spec(execute_mnesia_transaction/2 :: (thunk(A), fun ((A, boolean()) -> B)) -> B). --spec(execute_mnesia_transaction/3 :: - (thunk(A), fun ((A) -> B), fun ((A) -> B)) -> B). -spec(execute_mnesia_tx_with_tail/1 :: (thunk(fun ((boolean()) -> B))) -> B | (fun ((boolean()) -> B))). -spec(ensure_ok/2 :: (ok_or_error(), atom()) -> 'ok'). @@ -391,40 +388,30 @@ execute_mnesia_transaction(TxFun) -> %% Like execute_mnesia_transaction/1 with additional Pre- and Post- -%% commit functions -execute_mnesia_transaction(TxFun, PreCommit, PostCommit) -> +%% commit function +execute_mnesia_transaction(TxFun, PrePostCommitFun) -> case mnesia:is_transaction() of true -> throw(unexpected_transaction); false -> ok end, - PostCommit(execute_mnesia_transaction( - fun () -> - PreCommit(TxFun()) - end)). - -%% Like execute_mnesia_transaction/3 with similar Pre- and PostCommit funs -execute_mnesia_transaction(TxFun, PrePostCommitFun) -> - execute_mnesia_transaction(TxFun, - fun (Result) -> - PrePostCommitFun(Result, true), - Result - end, - fun (Result) -> - PrePostCommitFun(Result, false) - end). + PrePostCommitFun(execute_mnesia_transaction( + fun () -> + Result = TxFun(), + PrePostCommitFun(Result, true), + Result + end), false). %% Like execute_mnesia_transaction/2, but TxFun is expected to return a %% TailFun which gets called immediately before and after the tx commit execute_mnesia_tx_with_tail(TxFun) -> case mnesia:is_transaction() of true -> execute_mnesia_transaction(TxFun); - false -> TailFun = - execute_mnesia_transaction( - fun () -> - TailFun = TxFun(), - TailFun(true), - TailFun - end), + false -> TailFun = execute_mnesia_transaction( + fun () -> + TailFun1 = TxFun(), + TailFun1(true), + TailFun1 + end), TailFun(false) end. |