File: unknown_erlang_alias_func.txt

package info (click to toggle)
erlang 1%3A27.3.4.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 225,000 kB
  • sloc: erlang: 1,658,966; ansic: 405,769; cpp: 177,850; xml: 82,435; makefile: 15,031; sh: 14,401; lisp: 9,812; java: 8,603; asm: 6,541; perl: 5,836; python: 5,484; sed: 72
file content (59 lines) | stat: -rw-r--r-- 1,972 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

  alias()

Since:
  OTP 24.0

  There is no documentation for alias([])

  alias(Opts)

Since:
  OTP 24.0

  Create an alias which can be used when sending messages to the
  process that created the alias. When the alias has been
  deactivated, messages sent using the alias will be dropped. An
  alias can be deactivated using unalias/1.

  Currently available options for alias/1:

   • explicit_unalias - The alias can only be deactivated via a
     call to unalias/1. This is also the default behaviour if
     no options are passed or if alias/0 is called.

   • reply - The alias will be automatically deactivated when a
     reply message sent via the alias is received. The alias can
     also still be deactivated via a call to unalias/1.

  Example:

    server() ->
        receive
            {request, AliasReqId, Request} ->
                Result = perform_request(Request),
                AliasReqId ! {reply, AliasReqId, Result}
        end,
        server().
    
    client(ServerPid, Request) ->
        AliasReqId = alias([reply]),
        ServerPid ! {request, AliasReqId, Request},
        %% Alias will be automatically deactivated if we receive a reply
        %% since we used the 'reply' option...
        receive
            {reply, AliasReqId, Result} -> Result
        after 5000 ->
                unalias(AliasReqId),
                %% Flush message queue in case the reply arrived
                %% just before the alias was deactivated...
                receive {reply, AliasReqId, Result} -> Result
                after 0 -> exit(timeout)
                end
        end.

  Note that both the server and the client in this example must be
  executing on at least OTP 24 systems in order for this to work.

  For more information on process aliases see the Process Aliases
  section of the Erlang Reference Manual.