aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRaimo Niskanen <[email protected]>2016-02-19 09:39:46 +0100
committerRaimo Niskanen <[email protected]>2016-02-19 09:39:46 +0100
commitfc1e649e3613f18dec8514921d0439ddcca73bdb (patch)
treec450dbb70177f21cb30ef99962fa4fa728acf774 /lib
parent65767cfc36cf8658b45d68b3c17d4bd612198165 (diff)
downloadotp-fc1e649e3613f18dec8514921d0439ddcca73bdb.tar.gz
otp-fc1e649e3613f18dec8514921d0439ddcca73bdb.tar.bz2
otp-fc1e649e3613f18dec8514921d0439ddcca73bdb.zip
Add reply([Reply])
Diffstat (limited to 'lib')
-rw-r--r--lib/stdlib/doc/src/gen_statem.xml5
-rw-r--r--lib/stdlib/src/gen_statem.erl7
-rw-r--r--lib/stdlib/test/gen_statem_SUITE.erl10
3 files changed, 15 insertions, 7 deletions
diff --git a/lib/stdlib/doc/src/gen_statem.xml b/lib/stdlib/doc/src/gen_statem.xml
index f66f399137..5f9ec6736e 100644
--- a/lib/stdlib/doc/src/gen_statem.xml
+++ b/lib/stdlib/doc/src/gen_statem.xml
@@ -892,7 +892,10 @@ erlang:'!' -----> Module:StateName/5
</seealso> argument to the
<seealso marker="#state_function">state function</seealso>.
<c><anno>Client</anno></c> and <c><anno>Reply</anno></c>
- an also be specified using <c><anno>ReplyOperation</anno></c>.
+ can also be specified using a
+ <seealso marker="#type-reply_operation">
+ <c>reply_operation()</c>
+ </seealso> and multiple replies with a list of them.
</p>
<note>
<p>A reply sent with this function will not be visible
diff --git a/lib/stdlib/src/gen_statem.erl b/lib/stdlib/src/gen_statem.erl
index 3da4443f13..8aa8afd091 100644
--- a/lib/stdlib/src/gen_statem.erl
+++ b/lib/stdlib/src/gen_statem.erl
@@ -389,9 +389,12 @@ call(ServerRef, Request, Timeout) ->
end.
%% Reply from a state machine callback to whom awaits in call/2
--spec reply(ReplyOperation :: reply_operation()) -> ok.
+-spec reply([reply_operation()] | reply_operation()) -> ok.
reply({reply,{_To,_Tag}=Client,Reply}) ->
- reply(Client, Reply).
+ reply(Client, Reply);
+reply(Replies) when is_list(Replies) ->
+ [reply(Reply) || Reply <- Replies],
+ ok.
%%
-spec reply(Client :: client(), Reply :: term()) -> ok.
reply({To,Tag}, Reply) ->
diff --git a/lib/stdlib/test/gen_statem_SUITE.erl b/lib/stdlib/test/gen_statem_SUITE.erl
index 92dc59e843..4ac4acd189 100644
--- a/lib/stdlib/test/gen_statem_SUITE.erl
+++ b/lib/stdlib/test/gen_statem_SUITE.erl
@@ -1153,7 +1153,8 @@ idle(cast, {connect,Pid}, _, _, Data) ->
Pid ! accept,
{next_state,wfor_conf,Data};
idle({call,From}, connect, _, _, Data) ->
- {next_state,wfor_conf,Data,[{reply,From,accept}]};
+ gen_statem:reply(From, accept),
+ {next_state,wfor_conf,Data};
idle(cast, badreturn, _, _, _Data) ->
badreturn;
idle({call,_From}, badreturn, _, _, _Data) ->
@@ -1161,7 +1162,8 @@ idle({call,_From}, badreturn, _, _, _Data) ->
idle({call,From}, {delayed_answer,T}, _, _, Data) ->
receive
after T ->
- throw({keep_state,Data,{reply,From,delayed}})
+ gen_statem:reply({reply,From,delayed}),
+ throw({keep_state,Data})
end;
idle({call,From}, {timeout,Time}, _, State, _Data) ->
{next_state,timeout,{From,Time},
@@ -1200,8 +1202,8 @@ timeout2(_, _, _, State, Data) ->
{next_state,State,Data}.
timeout3(info, {timeout,TRef2,Result}, _, _, {From,TRef2}) ->
- {next_state,idle,state,
- [{reply,From,Result}]};
+ gen_statem:reply([{reply,From,Result}]),
+ {next_state,idle,state};
timeout3(_, _, _, State, Data) ->
{next_state,State,Data}.