livebook/lib/live_book/evaluator_supervisor.ex
Jonatan Kłosko 00b06f6e7a
Define session data structure and implement several operations (#6)
* Define session data structure and some operations

* Make code evaluation request async, so that we don't need an intermediary process

* Simplify id typespecs

* Make operation application composable

* Keep a separate evaluation queue per section and actually support concurrent evaluation

* Small fixes

* Validate queued cell type and set evaluation timestamp

* Apply review suggestions

* Add tests

* Store evaluating_cell_id instead of section status

* Add dynamic supervisor for managing evaluator processes

* Some fixes

* Refactor operation application

* Upon cell deletion mark dependent cells as stale
2021-01-13 14:39:04 +01:00

43 lines
1,003 B
Elixir

defmodule LiveBook.EvaluatorSupervisor do
@moduledoc false
# Supervisor responsible for dynamically spawning
# and terminating terminator server processes.
use DynamicSupervisor
alias LiveBook.Evaluator
@name __MODULE__
def start_link(opts \\ []) do
DynamicSupervisor.start_link(__MODULE__, opts, name: @name)
end
@impl true
def init(_opts) do
DynamicSupervisor.init(strategy: :one_for_one)
end
@doc """
Spawns a new evaluator.
"""
@spec start_evaluator() :: {:ok, Evaluator.t()} | {:error, any()}
def start_evaluator() do
case DynamicSupervisor.start_child(@name, Evaluator) do
{:ok, pid} -> {:ok, pid}
{:ok, pid, _} -> {:ok, pid}
:ignore -> {:error, :ignore}
{:error, reason} -> {:error, reason}
end
end
@doc """
Terminates the given evaluator.
"""
@spec terminate_evaluator(Evaluator.t()) :: :ok
def terminate_evaluator(evaluator) do
DynamicSupervisor.terminate_child(@name, evaluator)
:ok
end
end