Agent.cast
You're seeing just the function
cast
, go back to Agent module for more information.
Specs
Performs a cast (fire and forget) operation on the agent state.
The function fun
is sent to the agent
which invokes the function
passing the agent state. The return value of fun
becomes the new
state of the agent.
Note that cast
returns :ok
immediately, regardless of whether agent
(or
the node it should live on) exists.
Examples
iex> {:ok, pid} = Agent.start_link(fn -> 42 end)
iex> Agent.cast(pid, fn state -> state + 1 end)
:ok
iex> Agent.get(pid, fn state -> state end)
43
Specs
Performs a cast (fire and forget) operation on the agent state.
Same as cast/2
but a module, function, and arguments are expected
instead of an anonymous function. The state is added as first
argument to the given list of arguments.
Examples
iex> {:ok, pid} = Agent.start_link(fn -> 42 end)
iex> Agent.cast(pid, Kernel, :+, [12])
:ok
iex> Agent.get(pid, fn state -> state end)
54