Commits

Anonymous committed bae5946

Adding support for gen_fsm:sync_send_event/2,3

  • Participants
  • Parent commits b07a994

Comments (0)

Files changed (7)

File src/luke_phase.erl

    {handle_timeout, 1},
    {handle_input, 3},
    {handle_input_done, 1},
+   {handle_sync_event, 3},
    {handle_event, 2},
    {handle_info, 2},
    {terminate, 2}];
 executing(Event, #state{mod=PhaseMod, modstate=ModState}=State) ->
     handle_callback(async, PhaseMod:handle_event(Event, ModState), State).
 
+
 executing({inputs, Input}, _From, #state{mod=PhaseMod, modstate=ModState, flow_timeout=Timeout}=State) ->
-    handle_callback(sync, PhaseMod:handle_input(Input, ModState, Timeout), State).
+    handle_callback(sync, PhaseMod:handle_input(Input, ModState, Timeout), State);
+executing(Event, From, #state{mod=PhaseMod, modstate=ModState}=State) ->
+    case PhaseMod:handle_sync_event(Event, From, ModState) of
+        {reply, Reply, NewModState} ->
+            {reply, Reply, executing, State#state{modstate=NewModState}};
+        {noreply, NewModState} ->
+            {next_state, executing, State#state{modstate=NewModState}};
+        {stop, Reason, Reply, NewModState} ->
+            {stop, Reason, Reply, State#state{modstate=NewModState}};
+        {stop, Reason, NewModState} ->
+            {stop, Reason, State#state{modstate=NewModState}}
+    end.
 
 handle_event(_Event, StateName, State) ->
     {next_state, StateName, State}.
 
 handle_sync_event(_Event, _From, StateName, State) ->
     {reply, ignored, StateName, State}.
+
 handle_info(timeout, executing, #state{mod=Mod, modstate=ModState}=State) ->
     handle_callback(async, Mod:handle_timeout(ModState), State);
 handle_info(Info, _StateName, #state{mod=PhaseMod, modstate=ModState}=State) ->

File test/async_phase.erl

 -behaviour(luke_phase).
 
 -export([init/1, handle_input/3, handle_input_done/1, handle_event/2,
-         handle_timeout/1, handle_info/2, terminate/2]).
+         handle_sync_event/3, handle_timeout/1, handle_info/2, terminate/2]).
 
 -record(state, {}).
 
 handle_event(_Event, State) ->
     {no_output, State}.
 
+handle_sync_event(_Event, _From, State) ->
+    {reply, ignored, State}.
+
 handle_timeout(State) ->
     {no_output, State}.
 

File test/map_phase.erl

 -include_lib("eunit/include/eunit.hrl").
 
 -export([init/1, handle_input/3, handle_input_done/1, handle_event/2,
-         handle_timeout/1, handle_info/2, terminate/2]).
+         handle_sync_event/3, handle_timeout/1, handle_info/2, terminate/2]).
 
 -record(state, {workers=[], done=false}).
 
 handle_event(_Event, State) ->
     {no_output, State}.
 
+handle_sync_event(_Event, _From, State) ->
+    {reply, ignored, State}.
+
 handle_timeout(State) ->
     {no_output, State}.
 

File test/reduce_phase.erl

 -behaviour(luke_phase).
 
 -export([init/1, handle_input/3, handle_input_done/1, handle_event/2,
-         handle_timeout/1, handle_info/2, terminate/2]).
+         handle_sync_event/3, handle_timeout/1, handle_info/2, terminate/2]).
 
 -record(state, {reduced=0}).
 
 handle_event(_Event, State) ->
     {no_output, State}.
 
+handle_sync_event(_Event, _From, State) ->
+    {reply, ignored, State}.
+
 handle_timeout(State) ->
     {no_output, State}.
 

File test/results_tests.erl

              test_util:verify_results(FlowId, none),
              test_util:assertDead([Pid|Phases]) end,
      fun() ->
+             {_FlowId, Pid, [Phase]} = test_util:start_flow(?SYNC_FLOW),
+             ?assertMatch(pong, gen_fsm:sync_send_event(Phase, ping)),
+             luke_flow:finish_inputs(Pid) end,
+     fun() ->
              {FlowId, Pid, Phases} = test_util:start_flow(?MAPRED_EMPTY),
              luke_flow:add_inputs(Pid, [a,b]),
              luke_flow:add_inputs(Pid, [a,b]),

File test/simple_phase.erl

 -behaviour(luke_phase).
 
 -export([init/1, handle_input/3, handle_input_done/1, handle_event/2,
-         handle_timeout/1, handle_info/2, terminate/2]).
+         handle_sync_event/3, handle_timeout/1, handle_info/2, terminate/2]).
 
 -record(state, {inputs=[]}).
 
 handle_event(_Event, State) ->
     {no_output, State}.
 
+handle_sync_event(_Event, _From, State) ->
+    {reply, ignored, State}.
+
 handle_timeout(State) ->
     {no_output, State}.
 

File test/tests.hrl

 
 -define(MAPRED_EMPTY, [{map_phase, [], []},
                        {reduce_phase, [{converge, 1}], []}]).
+
+-define(SYNC_FLOW, [{sync_phase, [], []}]).