Elixir MOM v0.5.3 MOM.RPC.Context

Stateful map.

It creates a process with a map to ease context storage and management.

Example:

iex> {:ok, ma} = start_link()
iex> set ma, "test", true
:ok
iex> get ma, "test"
true
iex> get ma, "does-not-exist"
nil
iex> delete ma, "test"
:ok
iex> get ma, "test"
nil
iex> stop ma
:ok

There is also some default value if MapAgent is nil, to allow some situations.

iex> get nil, :test, :default_value
:default_value
iex> set nil, :failure, :nok
** (ArgumentError) Invalid context

Summary

Functions

Returns the statefull value of k, or d as default

Puts a value into the MapAgent

Allows to update atomically a map into the context

Functions

debug(pid)
delete(ma, k)
get(ma, k, d \\ nil)

Returns the statefull value of k, or d as default

Allows to get from a nil MapAgent the default value, so methods can be used on both context clients and contextless.

set(ma, k, v)

Puts a value into the MapAgent.

In oposittion to get, if user tries to put it will fail (Agent fail actually)

start_link(options \\ [])
stop(ma, reason \\ :normal)
update(ctx, k, map)

Allows to update atomically a map into the context

Example:

iex> {:ok, c} = start_link()
iex> update c, :test, a: 1
iex> get c, :test
%{ a: 1 }
iex> update c, :test, [a: nil]
iex> get c, :test
%{}
iex> update c, :test, [a: 1, b: 2, c: nil]
iex> get c, :test
%{ a: 1, b: 2 }

Also can bu strings

iex> {:ok, c} = start_link()
iex> update c, :test, [{"string", 1}]
iex> get c, :test
%{ "string" => 1 }