glixir/agent
Types
Errors that can occur with Agents
pub type AgentError {
StartError(reason: String)
Timeout
AgentDown
DecodeError(String)
}
Constructors
-
StartError(reason: String)
-
Timeout
-
AgentDown
-
DecodeError(String)
Values
pub fn get(
agent: Agent,
fun: fn(a) -> b,
decoder: decode.Decoder(b),
) -> Result(b, AgentError)
Get the current state
Requires a decoder for the expected type b
.
pub fn get_and_update(
agent: Agent,
fun: fn(a) -> #(b, a),
decoder: decode.Decoder(b),
) -> Result(b, AgentError)
Get and update in one operation
Requires a decoder for the expected type b
.
pub fn get_timeout(
agent: Agent,
fun: fn(a) -> b,
timeout: Int,
decoder: decode.Decoder(b),
) -> Result(b, AgentError)
Get with custom timeout
Requires a decoder for the expected type b
.
pub fn start(initial_fun: fn() -> a) -> Result(Agent, AgentError)
Start a new Agent with initial state
pub fn start_named(
name: String,
initial_fun: fn() -> a,
) -> Result(Agent, AgentError)
Start an Agent with a name
pub fn update(
agent: Agent,
fun: fn(a) -> a,
) -> Result(Nil, AgentError)
Update the state synchronously