Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle user update asynchronously #22

Open
upstarter opened this issue May 8, 2020 · 0 comments
Open

Handle user update asynchronously #22

upstarter opened this issue May 8, 2020 · 0 comments

Comments

@upstarter
Copy link
Owner

upstarter commented May 8, 2020

Find a way to pass a function to state in user-defined update function so that the update can be run async as a Task so subsequent ticks will return :bh_running until the task completes (which sets the resulting status). This makes the agent reactive. Or is there a better more elixir way to do this? I'm thinking similar to this:

  def handle_cast({:run, fun}, state) do
    Task.async(fun) # sends a message back to the automaton when completed
    {:noreply, state}
  end

  # handle_info/2 receives generic messages from the Task processes
  def handle_info({_task, {:ok, result}}, state) do
    new_state = %{state | status: result}
    {:noreply, new_state}
  end

  def handle_info({_task, {:error, reason}}, state) do
    state = %{state | status: :bh_failure, fail_reason: reason}
    {:noreply, state}
  end
@upstarter upstarter created this issue from a note in The Automata Project (To do) May 8, 2020
@upstarter upstarter added the core label May 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

1 participant