diff options
| -rw-r--r-- | src/mirrored_supervisor.erl | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/mirrored_supervisor.erl b/src/mirrored_supervisor.erl index 9bc350b2e4..5e7ce63906 100644 --- a/src/mirrored_supervisor.erl +++ b/src/mirrored_supervisor.erl @@ -444,10 +444,17 @@ start(Delegate, ChildSpec) -> apply(?SUPERVISOR, start_child, [Delegate, ChildSpec]). stop(Delegate, Id) -> + case mnesia:transaction(fun() -> check_stop(Delegate, Id) end) of + {atomic, deleted} -> apply(?SUPERVISOR, delete_child, [Delegate, Id]); + {atomic, running} -> {error, running}; + {aborted, E} -> {error, E} + end. + +check_stop(Delegate, Id) -> case child(Delegate, Id) of - undefined -> {atomic, ok} = mnesia:transaction(fun() -> delete(Id) end), - apply(?SUPERVISOR, delete_child, [Delegate, Id]); - _ -> {error, running} + undefined -> delete(Id), + deleted; + _ -> running end. id({Id, _, _, _, _, _}) -> Id. |
