概要
paiza.ioでelixirやってみた。
Process使ってみた。
サンプルコード
Process.put(:comments, ["comment", "other comment"])
Process.delete(:comments)
|> IO.inspect
Process.delete(:comments)
|> IO.inspect
pid = spawn(fn ->
1 + 2
end)
Process.exit(pid, :kill)
|> IO.inspect
Process.get(:locale, "pt")
|> IO.inspect
Process.put(:locale, "fr")
|> IO.inspect
Process.get(:locale, "pt")
|> IO.inspect
:locale in Process.get_keys()
|> IO.inspect
Process.put(:locale, "pt")
|> IO.inspect
:locale in Process.get_keys()
|> IO.inspect
Process.group_leader()
|> IO.inspect
Process.list()
|> IO.inspect
pid = spawn(fn ->
1 + 2
end)
|> IO.inspect
Process.monitor(pid)
|> IO.inspect
Process.exit(pid, :kill)
|> IO.inspect
receive do
msg -> msg
end
|> IO.inspect
Process.put(:locale, "en")
|> IO.inspect
Process.put(:locale, "fr")
|> IO.inspect
Process.register(self(), :test)
|> IO.inspect
send(:test, :hello)
|> IO.inspect
#Process.register(self(), :test)
#|> IO.inspect
Process.registered()
|> IO.inspect
Process.send({:name, :node_that_does_not_exist}, :hi, [:noconnect])
|> IO.inspect
timer_ref = Process.send_after(pid, :hi, 100)
|> IO.inspect
Process.spawn(fn ->
1 + 2
end, [:monitor])
|> IO.inspect
Process.spawn(fn ->
1 + 2
end, [:link])
|> IO.inspect
#Process.register(self(), :test)
#|> IO.inspect
Process.unregister(:test)
|> IO.inspect
Process.register(self(), :test)
|> IO.inspect
Process.whereis(:test)
|> IO.inspect
実行結果
["comment", "other comment"]
nil
true
"pt"
nil
"fr"
true
"fr"
true
#PID<0.62.0>
[#PID<0.0.0>, #PID<0.1.0>, #PID<0.2.0>, #PID<0.3.0>, #PID<0.4.0>, #PID<0.5.0>,
#PID<0.6.0>, #PID<0.8.0>, #PID<0.9.0>, #PID<0.41.0>, #PID<0.43.0>,
#PID<0.45.0>, #PID<0.46.0>, #PID<0.48.0>, #PID<0.49.0>, #PID<0.50.0>,
#PID<0.52.0>, #PID<0.53.0>, #PID<0.54.0>, #PID<0.55.0>, #PID<0.56.0>,
#PID<0.57.0>, #PID<0.58.0>, #PID<0.59.0>, #PID<0.60.0>, #PID<0.61.0>,
#PID<0.62.0>, #PID<0.63.0>, #PID<0.64.0>, #PID<0.65.0>, #PID<0.66.0>,
#PID<0.67.0>, #PID<0.68.0>, #PID<0.77.0>, #PID<0.78.0>, #PID<0.79.0>,
#PID<0.80.0>, #PID<0.81.0>, #PID<0.83.0>, #PID<0.84.0>, #PID<0.85.0>,
#PID<0.86.0>, #PID<0.87.0>, #PID<0.88.0>, #PID<0.89.0>, #PID<0.92.0>,
#PID<0.93.0>]
#PID<0.96.0>
#Reference<0.665306083.2005925890.40514>
true
{:DOWN, #Reference<0.665306083.2005925890.40514>, :process, #PID<0.96.0>,
:noproc}
"pt"
"en"
true
:hello
[:code_server, :file_server_2, :erts_code_purger, :kernel_safe_sup,
:application_controller, :erl_signal_server, :kernel_refc, :standard_error_sup,
Logger, :inet_db, Logger.Supervisor, :test, :logger_sup, :logger,
:logger_proxy, :user, :standard_error, :logger_handler_watcher, :global_group,
:elixir_sup, :elixir_config, :rex, Logger.BackendSupervisor, :kernel_sup,
:erl_prim_loader, :global_name_server, :init, :elixir_code_server]
:noconnect
#Reference<0.665306083.2005925890.40529>
{#PID<0.97.0>, #Reference<0.665306083.2005925890.40531>}
#PID<0.98.0>
true
true
#PID<0.92.0>
×
成果物
以上。