Skip to content

Commit

Permalink
JSON actor example
Browse files Browse the repository at this point in the history
  • Loading branch information
eliasdarruda committed May 13, 2023
1 parent 505ef6d commit 7d31eba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
defmodule SpawnSdkExample.Actors.JsonActor do
use SpawnSdk.Actor,
name: "json",
state_type: :json,
deactivate_timeout: 60_000,
snapshot_timeout: 2_000

defmodule State do
@derive {Jason.Encoder, only: [:value]}
defstruct [:value, :should_ignore]
end

defact sum(%{value: value}, %Context{state: state} = ctx) do
new_value = (value || 0) + (state.value || 0)

response = %{total_value: new_value}

Value.of()
|> Value.response(response)
|> Value.state(%State{value: new_value, should_ignore: "ignore"})
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defmodule SpawnSdkExample.Application do
system: "spawn-system",
actors: [
SpawnSdkExample.Actors.JoeActor,
SpawnSdkExample.Actors.JsonActor,
SpawnSdkExample.Actors.ClockActor,
SpawnSdkExample.Actors.AbstractActor,
SpawnSdkExample.Actors.PooledActor
Expand Down

0 comments on commit 7d31eba

Please sign in to comment.