From 2cd331fec3e08799bdd482399e8c969102e1142f Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Thu, 17 Mar 2016 16:05:35 +0100 Subject: Change Caller -> From as suggested by Fred Hebert --- lib/stdlib/doc/src/gen_statem.xml | 50 +++++++++++++++++++-------------------- lib/stdlib/src/gen_statem.erl | 46 +++++++++++++++++------------------ 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/lib/stdlib/doc/src/gen_statem.xml b/lib/stdlib/doc/src/gen_statem.xml index 90d2326954..83f7dc1c8a 100644 --- a/lib/stdlib/doc/src/gen_statem.xml +++ b/lib/stdlib/doc/src/gen_statem.xml @@ -253,23 +253,23 @@ init([]) -> %%% State functions -off({call,Caller}, push, Data) -> +off({call,From}, push, Data) -> %% Go to 'on', increment count and reply %% that the resulting status is 'on' - {next_state,on,Data+1,[{reply,Caller,on}]}; + {next_state,on,Data+1,[{reply,From,on}]}; off(EventType, EventContent, Data) -> handle_event(EventType, EventContent, Data). -on({call,Caller}, push, Data) -> +on({call,From}, push, Data) -> %% Go to 'off' and reply that the resulting status is 'off' - {next_state,off,Data,[{reply,Caller,off}]}; + {next_state,off,Data,[{reply,From,off}]}; on(EventType, EventContent, Data) -> handle_event(EventType, EventContent, Data). %% Handle events common to all states -handle_event({call,Caller}, get_count, Data) -> +handle_event({call,From}, get_count, Data) -> %% Reply with the current count - {keep_state,Data,[{reply,Caller,Data}]}; + {keep_state,Data,[{reply,From,Data}]}; handle_event(_, _, Data) -> %% Ignore all other events {keep_state,Data}. @@ -315,18 +315,18 @@ init([]) -> %%% Event handling -handle_event({call,Caller}, push, off, Data) -> +handle_event({call,From}, push, off, Data) -> %% Go to 'on', increment count and reply %% that the resulting status is 'on' - {next_state,on,Data+1,[{reply,Caller,on}]}; -handle_event({call,Caller}, push, on, Data) -> + {next_state,on,Data+1,[{reply,From,on}]}; +handle_event({call,From}, push, on, Data) -> %% Go to 'off' and reply that the resulting status is 'off' - {next_state,off,Data,[{reply,Caller,off}]}; + {next_state,off,Data,[{reply,From,off}]}; %% %% Event handling common to all states -handle_event({call,Caller}, get_count, State, Data) -> +handle_event({call,From}, get_count, State, Data) -> %% Reply with the current count - {next_state,State,Data,[{reply,Caller,Data}]}; + {next_state,State,Data,[{reply,From,Data}]}; handle_event(_, _, State, Data) -> %% Ignore all other events {next_state,State,Data}. @@ -429,12 +429,12 @@ handle_event(_, _, State, Data) -> - +

Destination to use when replying through for example the - action() {reply,Caller,Reply} + action() {reply,From,Reply} to a process that has called the gen_statem server using call/2. @@ -483,7 +483,7 @@ handle_event(_, _, State, Data) ->

External events are of 3 different type: - {call,Caller}, cast or info. + {call,From}, cast or info. Calls (synchronous) and casts @@ -739,9 +739,9 @@ handle_event(_, _, State, Data) ->

Reply to a caller waiting for a reply in call/2. - Caller must be the term from the + From must be the term from the - {call,Caller} + {call,From} argument to the state function. @@ -1029,14 +1029,14 @@ handle_event(_, _, State, Data) -> The gen_statem will call the state function with event_type() - {call,Caller} and event content + {call,From} and event content Request.

A Reply is generated when a state function returns with - {reply,Caller,Reply} as one + {reply,From,Reply} as one action(), and that Reply becomes the return value of this function. @@ -1100,13 +1100,13 @@ handle_event(_, _, State, Data) -> state function.

- Caller must be the term from the + From must be the term from the - {call,Caller} + {call,From} argument to the state function. - Caller and Reply + From and Reply can also be specified using a reply_action() @@ -1340,15 +1340,15 @@ handle_event(_, _, State, Data) ->

If EventType is - {call,Caller} + {call,From} the caller is waiting for a reply. The reply can be sent from this or from any other state function - by returning with {reply,Caller,Reply} in + by returning with {reply,From,Reply} in Actions, in Replies or by calling - reply(Caller, Reply). + reply(From, Reply).

If this function returns with a next state that diff --git a/lib/stdlib/src/gen_statem.erl b/lib/stdlib/src/gen_statem.erl index 92e26bd7ed..82ac5824eb 100644 --- a/lib/stdlib/src/gen_statem.erl +++ b/lib/stdlib/src/gen_statem.erl @@ -59,7 +59,7 @@ %%% Interface functions. %%%========================================================================== --type caller() :: +-type from() :: {To :: pid(), Tag :: term()}. % Reply-to specifier for call -type state() :: @@ -71,7 +71,7 @@ -type data() :: term(). -type event_type() :: - {'call',Caller :: caller()} | 'cast' | + {'call',From :: from()} | 'cast' | 'info' | 'timeout' | 'internal'. -type callback_mode() :: 'state_functions' | 'handle_event_function'. @@ -125,7 +125,7 @@ EventContent :: term()}. -type reply_action() :: {'reply', % Reply to a caller - Caller :: caller(), Reply :: term()}. + From :: from(), Reply :: term()}. -type state_function_result() :: {'next_state', % {next_state,NextStateName,NewData,[]} @@ -253,13 +253,13 @@ callback_mode(CallbackMode) -> false end. %% -caller({Pid,_}) when is_pid(Pid) -> +from({Pid,_}) when is_pid(Pid) -> true; -caller(_) -> +from(_) -> false. %% -event_type({call,Caller}) -> - caller(Caller); +event_type({call,From}) -> + from(From); event_type(Type) -> case Type of cast -> @@ -378,7 +378,7 @@ cast(ServerRef, Msg) when is_pid(ServerRef) -> send(ServerRef, wrap_cast(Msg)). %% Call a state machine (synchronous; a reply is expected) that -%% arrives with type {call,Caller} +%% arrives with type {call,From} -spec call(ServerRef :: server_ref(), Request :: term()) -> Reply :: term(). call(ServerRef, Request) -> call(ServerRef, Request, infinity). @@ -437,12 +437,12 @@ call(ServerRef, Request, Timeout) -> %% Reply from a state machine callback to whom awaits in call/2 -spec reply([reply_action()] | reply_action()) -> ok. -reply({reply,Caller,Reply}) -> - reply(Caller, Reply); +reply({reply,From,Reply}) -> + reply(From, Reply); reply(Replies) when is_list(Replies) -> replies(Replies). %% --spec reply(Caller :: caller(), Reply :: term()) -> ok. +-spec reply(From :: from(), Reply :: term()) -> ok. reply({To,Tag}, Reply) when is_pid(To) -> Msg = {Tag,Reply}, try To ! Msg of @@ -509,8 +509,8 @@ enter_loop(Module, Opts, CallbackMode, State, Data, Server, Actions) -> wrap_cast(Event) -> {'$gen_cast',Event}. -replies([{reply,Caller,Reply}|Replies]) -> - reply(Caller, Reply), +replies([{reply,From,Reply}|Replies]) -> + reply(From, Reply), replies(Replies); replies([]) -> ok. @@ -782,8 +782,8 @@ loop_receive(Parent, Debug, #{timer := Timer} = S) -> end, Event = case Msg of - {'$gen_call',Caller,Request} -> - {{call,Caller},Request}; + {'$gen_call',From,Request} -> + {{call,From},Request}; {'$gen_cast',E} -> {cast,E}; _ -> @@ -983,10 +983,10 @@ loop_event_actions( ?TERMINATE( error, {bad_action,Action}, Debug, S, [Event|Events]); %% Actual actions - {reply,Caller,Reply} -> - case caller(Caller) of + {reply,From,Reply} -> + case from(From) of true -> - NewDebug = do_reply(Debug, S, Caller, Reply), + NewDebug = do_reply(Debug, S, From, Reply), loop_event_actions( Parent, NewDebug, S, Events, Event, State, NextState, NewData, Actions, @@ -1101,17 +1101,17 @@ do_reply_then_terminate(Class, Reason, Stacktrace, Debug, S, Q, []) -> do_reply_then_terminate( Class, Reason, Stacktrace, Debug, S, Q, [R|Rs]) -> case R of - {reply,{_To,_Tag}=Caller,Reply} -> - NewDebug = do_reply(Debug, S, Caller, Reply), + {reply,{_To,_Tag}=From,Reply} -> + NewDebug = do_reply(Debug, S, From, Reply), do_reply_then_terminate( Class, Reason, Stacktrace, NewDebug, S, Q, Rs); _ -> [error,{bad_action,R},?STACKTRACE(),Debug] end. -do_reply(Debug, S, Caller, Reply) -> - reply(Caller, Reply), - sys_debug(Debug, S, {out,Reply,Caller}). +do_reply(Debug, S, From, Reply) -> + reply(From, Reply), + sys_debug(Debug, S, {out,Reply,From}). terminate( -- cgit v1.2.3