global
demonstration
On terminal 1:
$ iex --name t1@127.0.0.1
On terminal 2:
$ iex --name t2@127.0.0.1
From either t1 or t2, connect to the other one.
# from t2
iex> Node.connect(:"t1@127.0.0.1")
true
Check from either instance.
# from t2
iex> Node.list()
[:"t1@127.0.0.1"]
# from t1
iex> Node.list()
[:"t2@127.0.0.1"]
# from `t1`
Agent.start_link(fn -> %{t1: true} end, name: {:global, {:t1, "t1 description"}})
# from `t2`
Agent.get({:global, {:t1, "t1 description"}}, & &1)
t1:
~ :> iex --name t1@127.0.0.1
Erlang/OTP 21 [erts-10.0.5] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [hipe]
Interactive Elixir (1.7.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(t1@127.0.0.1)1> Node.list()
[:"t2@127.0.0.1"]
iex(t1@127.0.0.1)2> Agent.start_link(fn -> %{t1: true} end, name: {:global, {:t1, "t1 description"}})
{:ok, #PID<0.112.0>}
iex(t1@127.0.0.1)3>
t2:
~ :> iex --name t2@127.0.0.1
Erlang/OTP 21 [erts-10.0.5] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [hipe]
Interactive Elixir (1.7.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(t2@127.0.0.1)1> Node.connect(:"t1@127.0.0.1")
true
iex(t2@127.0.0.1)2> Agent.get({:global, {:t1, "t1 description"}}, & &1)
%{t1: true}
iex(t2@127.0.0.1)3>
|--------| |--------|
| t1 |----| t2 |
|--------| |--------|
| | | |
| At1 | | |
| | | |
|--------| |--------|
- At1 -> Agent named t1
t2 can communicate with At1