From a320863d6a4cfae75105cd2913a4a389d5860b17 Mon Sep 17 00:00:00 2001 From: Dan Gudmundsson Date: Fri, 22 Sep 2017 10:02:17 +0200 Subject: initial gen_server doc suggestion --- lib/stdlib/doc/src/gen_server.xml | 72 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/lib/stdlib/doc/src/gen_server.xml b/lib/stdlib/doc/src/gen_server.xml index da74e793e6..0e12a05df2 100644 --- a/lib/stdlib/doc/src/gen_server.xml +++ b/lib/stdlib/doc/src/gen_server.xml @@ -53,6 +53,7 @@ gen_server:start_link -----> Module:init/1 gen_server:stop -----> Module:terminate/2 gen_server:call +gen_server:async_call gen_server:multi_call -----> Module:handle_call/3 gen_server:cast @@ -174,6 +175,48 @@ gen_server:abcast -----> Module:handle_cast/2 + + async_call(ServerRef, Request) -> Promise + Make a asynchronous call to a generic server. + + ServerRef = Name | {Name,Node} | {global,GlobalName} +   | {via,Module,ViaName} | pid() +  Node = atom() +  GlobalName = ViaName = term() + Promise = reference() + Timeout = int()>0 | infinity + Request = term() + + +

Makes a asynchronous call to the ServerRef of the + gen_server process and returns a handle Promise. + The gen_server process calls + + Module:handle_call/3 to handle the request.

+

ServerRef can be any of the following:

+ + The pid + Name, if the gen_server process is locally + registered + {Name,Node}, if the gen_server process is locally + registered at another node + {global,GlobalName}, if the gen_server process is + globally registered + {via,Module,ViaName}, if the gen_server process is + registered through an alternative process registry + +

Request is any term that is passed as one of + the arguments to Module:handle_call/3.

+

The return value Promise is intended to be used with + yield/1,2. Note, + if the reply message is received and kept without invoking + yield/1,2, the + monitor reference needs to be cleaned up with + erlang:demonitor(Promise, [flush]). +

+
+
+ cast(ServerRef, Request) -> ok Send an asynchronous request to a generic server. @@ -501,6 +544,35 @@ gen_server:abcast -----> Module:handle_cast/2 + + + yield(Promise) -> {reply, Reply} + yield(Promise, Timeout) -> {reply, Reply} | timeout + Wait for a reply from a server. + + Promise = reference() + Reply = term() + Timeout = timeout() + + +

This function is used to wait for a reply on a request made with + async_call/2 + from the gen_server process.

+

Timeout is an integer greater then or equal to zero + that specifies how many milliseconds to wait for an reply, or + the atom infinity to wait indefinitely. Defaults to + infinity. If no reply is received within the specified + time, the function returns timeout and no cleanup is + done, and thus the function can be invoked repeatedly until a + reply is returned. Otherwise do a cleanup the request with + erlang:demonitor(Promise, [flush]).

+

The return value Reply is defined in the return value + of Module:handle_call/3.

+

This function can fail for many reasons, including that the + called gen_server process dying before or during the call.

+
+
+
Callback Functions

The following functions -- cgit v1.2.1