Skip to content
Erlang Agent implementation
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
test
.gitignore
.travis.yml
LICENSE
Makefile
README.md
rebar.config
rebar.lock
rebar3

README.md

agent

Build Status

Implementation of agent primitive for simple state management.

Build

$ make

Tests

$ make test

Usage

{ok, Agent} = agent:start_link(fun() -> 123 end),

123 = agent:get(Agent),
246 = agent:get(Agent, fun(S) -> S * 2 end),

124 = agent:get_and_update(Agent, fun(S) -> {S+1, S+2} end),
125 = agent:get(Agent),

ok = agent:update(Agent, fun(S) -> S + 5 end),
130 = agent:get(Agent),

ok = agent:update_async(Agent, fun(S) -> S + 5 end),
timer:sleep(10),
135 = agent:get(Agent),

agent:stop(Agent).
You can’t perform that action at this time.