Agent.get_and_update

You're seeing just the function get_and_update, go back to Agent module for more information.
Link to this function

get_and_update(agent, fun, timeout \\ 5000)

View Source

Specs

get_and_update(agent(), (state() -> {a, state()}), timeout()) :: a when a: var

Gets and updates the agent state in one operation via the given anonymous function.

The function fun is sent to the agent which invokes the function passing the agent state. The function must return a tuple with two elements, the first being the value to return (that is, the "get" value) and the second one being the new state of the agent.

timeout is an integer greater than zero which specifies how many milliseconds are allowed before the agent executes the function and returns the result value, or the atom :infinity to wait indefinitely. If no result is received within the specified time, the function call fails and the caller exits.

Examples

iex> {:ok, pid} = Agent.start_link(fn -> 42 end)
iex> Agent.get_and_update(pid, fn state -> {state, state + 1} end)
42
iex> Agent.get(pid, fn state -> state end)
43
Link to this function

get_and_update(agent, module, fun, args, timeout \\ 5000)

View Source

Specs

get_and_update(agent(), module(), atom(), [term()], timeout()) :: any()

Gets and updates the agent state in one operation via the given function.

Same as get_and_update/3 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.