mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-09-10 06:54:28 +08:00
* 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
43 lines
1,003 B
Elixir
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
|