This is the Elixir code that defines the actor simulation model:
# Create a pipeline with message forwarding
forward = fn msg, state ->
{:send, [{state.next, msg}], state}
end
simulation =
ActorSimulation.new(trace: true)
|> ActorSimulation.add_actor(:api,
send_pattern: {:periodic, 100, {:check_auth, :user123}},
targets: [:auth]
)
|> ActorSimulation.add_actor(:auth,
on_receive: forward,
initial_state: %{next: :database}
)
|> ActorSimulation.add_actor(:database,
on_receive: fn
{:check_auth, _user}, state ->
{:send, [{:api, {:auth_ok, :token456}}], state}
_, state ->
{:ok, state}
end
)
|> ActorSimulation.run(duration: 400)