Przeglądaj źródła

Fixed pending cleanup requests for ebb_operation_fsm.

Paul Downen 13 lat temu
rodzic
commit
acd1aa6218
1 zmienionych plików z 12 dodań i 5 usunięć
  1. 12 5
      src/ebb_operation_fsm.erl

+ 12 - 5
src/ebb_operation_fsm.erl

@@ -17,7 +17,8 @@
 
 -define(DICT, orddict).
 
--record(state, {mode, operation, out_arity, output, return_requests}).
+-record(state, {mode, operation, out_arity, output,
+		return_requests, pending_cleanup}).
 
 %%====================================================================
 %% API
@@ -61,7 +62,8 @@ cleanup(Op) ->
 %%--------------------------------------------------------------------
 init({Op, Mode}) ->
     State = #state{mode=Mode, out_arity=ebb_prim:out_arity(Op),
-		   output=?DICT:new(), return_requests=[]},
+		   output=?DICT:new(), return_requests=[],
+		   pending_cleanup=false},
     case start_operation(Op, Mode, self()) of
 	{ok, Pid} -> {ok, running, State#state{operation=Pid}};
 	ignore -> {ok, running, State};
@@ -83,20 +85,25 @@ init({Op, Mode}) ->
 
 running({out, N, Val},
 	State = #state{out_arity=Arity, output=Output,
-		       return_requests=Requests})
+		       return_requests=Requests, pending_cleanup=Clean})
   when N > 0, N =< Arity ->
     Output2 = ?DICT:store(N, Val, Output),
     State2 = State#state{output=Output2},
     case is_done(State2) of
 	true  -> send_out_requests(Requests, Output2),
-		 {next_state, finished, State2#state{return_requests=[]}};
+		 State3 = State2#state{return_requests=[]},
+		 case Clean of
+		     true  -> {stop, normal, State3};
+		     false -> {next_state, finished, State3}
+		 end;
 	false -> {next_state, running, State2}
     end;
 running({in, N, Arg}, State = #state{operation=Pid}) ->
     ebb_event:in(Pid, N, Arg),
     {next_state, running, State};
 running(cleanup, State) ->
-    {next_state, running, State}.
+    State2 = State#state{pending_cleanup=true},
+    {next_state, running, State2}.
 
 finished(cleanup, State) ->
     {stop, normal, State}.