-
Notifications
You must be signed in to change notification settings - Fork 0
/
learningdoc.txt
20 lines (10 loc) · 1.41 KB
/
learningdoc.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1) gen_server is started by calling genserverModule:start_link(). You need to call the genserverModule:start_link() method from either some supervisor or some other process.
2) start_link() calls the function gen_server:start_link/4 which ultimately spawns and links to a new process
3) gen_server:start_link must be used if the gen_server is part of a supervision tree, i.e. is started by a supervisor.
Example: gen_server:start_link({local, ch3}, ch3, [], []) => {ok, Pid}
The first argument {local, ch3} specifies the name. In this case, the gen_server will be locally registered as ch3.
If the name is omitted, the gen_server is not registered. Instead its pid must be used. The name could also be given as {global, Name}, in which case the gen_server is registered using global:register_name/2.
The second argument, ch3, is the name of the callback module, that is the module where the callback functions are located.
In this case, the interface functions (start_link, alloc and free) are located in the same module as the callback functions (init, handle_call and handle_cast). This is normally good programming practice, to have the code corresponding to one process contained in one module.
The third argument, [], is a term which is passed as-is to the callback function init. Here, init does not need any indata and ignores the argument.
The fourth argument, [], is a list of options. See gen_server(3) for available options.