Last active
November 14, 2023 15:07
-
-
Save satom99/f4057c8719bcb14c4a9ba739d3b957f8 to your computer and use it in GitHub Desktop.
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
defmodule Testing do | |
@behaviour :gen_statem | |
def test() do | |
{:ok, pid} = start_link() | |
:gen_statem.call(pid, :get_state) |> IO.inspect() | |
to_party(pid) | |
:gen_statem.call(pid, :get_state) |> IO.inspect() | |
:ok | |
end | |
def callback_mode() do | |
:handle_event_function | |
end | |
def start_link do | |
:gen_statem.start_link(__MODULE__, nil, []) | |
end | |
def init(nil = data) do | |
{:ok, :idle, data} | |
end | |
def to_party(pid) do | |
:gen_statem.call(pid, :to_party) | |
end | |
def handle_event(:enter, _old_state, :idle, data) do | |
IO.inspect("Entering idle state") | |
{:keep_state, data} | |
end | |
def handle_event(:enter, _old_state, :to_party, data) do | |
IO.inspect("Entering to_party state") | |
{:keep_state, data} | |
end | |
def handle_event({:call, from}, :to_party, :idle, data) do | |
{:next_state, :party, data, [{:reply, from, :ok}]} | |
end | |
def handle_event({:call, from}, :get_state, state, data) do | |
{:keep_state, data, [{:reply, from, state}]} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment