From 9db6054d674969fef314bf8676b6f9b583af3bef Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Tue, 12 Apr 2016 14:30:02 +0200 Subject: Fix missing short forms for event timeout --- lib/stdlib/src/gen_statem.erl | 75 +++++++++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 32 deletions(-) (limited to 'lib/stdlib/src/gen_statem.erl') diff --git a/lib/stdlib/src/gen_statem.erl b/lib/stdlib/src/gen_statem.erl index 9c1e126507..b3a149a569 100644 --- a/lib/stdlib/src/gen_statem.erl +++ b/lib/stdlib/src/gen_statem.erl @@ -942,12 +942,32 @@ loop_event_actions( State, NextState, NewData, [Action|Actions], Postpone, Hibernate, Timeout, NextEvents) -> case Action of + %% Actual actions + {reply,From,Reply} -> + case from(From) of + true -> + NewDebug = do_reply(Debug, S, From, Reply), + loop_event_actions( + Parent, NewDebug, S, Events, Event, + State, NextState, NewData, Actions, + Postpone, Hibernate, Timeout, NextEvents); + false -> + ?TERMINATE( + error, {bad_action,Action}, Debug, S, [Event|Events]) + end; + {next_event,Type,Content} -> + case event_type(Type) of + true -> + loop_event_actions( + Parent, Debug, S, Events, Event, + State, NextState, NewData, Actions, + Postpone, Hibernate, Timeout, + [{Type,Content}|NextEvents]); + false -> + ?TERMINATE( + error, {bad_action,Action}, Debug, S, [Event|Events]) + end; %% Actions that set options - postpone -> - loop_event_actions( - Parent, Debug, S, Events, Event, - State, NextState, NewData, Actions, - true, Hibernate, Timeout, NextEvents); {postpone,NewPostpone} when is_boolean(NewPostpone) -> loop_event_actions( Parent, Debug, S, Events, Event, @@ -956,11 +976,11 @@ loop_event_actions( {postpone,_} -> ?TERMINATE( error, {bad_action,Action}, Debug, S, [Event|Events]); - hibernate -> + postpone -> loop_event_actions( Parent, Debug, S, Events, Event, State, NextState, NewData, Actions, - Postpone, true, Timeout, NextEvents); + true, Hibernate, Timeout, NextEvents); {hibernate,NewHibernate} when is_boolean(NewHibernate) -> loop_event_actions( Parent, Debug, S, Events, Event, @@ -969,6 +989,11 @@ loop_event_actions( {hibernate,_} -> ?TERMINATE( error, {bad_action,Action}, Debug, S, [Event|Events]); + hibernate -> + loop_event_actions( + Parent, Debug, S, Events, Event, + State, NextState, NewData, Actions, + Postpone, true, Timeout, NextEvents); {timeout,infinity,_} -> % Clear timer - it will never trigger loop_event_actions( Parent, Debug, S, Events, Event, @@ -982,31 +1007,17 @@ loop_event_actions( {timeout,_,_} -> ?TERMINATE( error, {bad_action,Action}, Debug, S, [Event|Events]); - %% Actual actions - {reply,From,Reply} -> - case from(From) of - true -> - NewDebug = do_reply(Debug, S, From, Reply), - loop_event_actions( - Parent, NewDebug, S, Events, Event, - State, NextState, NewData, Actions, - Postpone, Hibernate, Timeout, NextEvents); - false -> - ?TERMINATE( - error, {bad_action,Action}, Debug, S, [Event|Events]) - end; - {next_event,Type,Content} -> - case event_type(Type) of - true -> - loop_event_actions( - Parent, Debug, S, Events, Event, - State, NextState, NewData, Actions, - Postpone, Hibernate, Timeout, - [{Type,Content}|NextEvents]); - false -> - ?TERMINATE( - error, {bad_action,Action}, Debug, S, [Event|Events]) - end; + infinity -> % Clear timer - it will never trigger + loop_event_actions( + Parent, Debug, S, Events, Event, + State, NextState, NewData, Actions, + Postpone, Hibernate, undefined, NextEvents); + Time when is_integer(Time), Time >= 0 -> + NewTimeout = {timeout,Time,Time}, + loop_event_actions( + Parent, Debug, S, Events, Event, + State, NextState, NewData, Actions, + Postpone, Hibernate, NewTimeout, NextEvents); _ -> ?TERMINATE( error, {bad_action,Action}, Debug, S, [Event|Events]) -- cgit v1.2.3