forked from eigr/spawn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
505ef6d
commit 7d31eba
Showing
2 changed files
with
23 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
spawn_sdk/spawn_sdk_example/lib/spawn_sdk_example/actors/json_actor.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters