Handle output even after cell finishes evaluation (#272)

This commit is contained in:
Jonatan Kłosko 2021-05-15 19:55:25 +02:00 committed by GitHub
parent 937597d6c0
commit 61a841a6d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 2 deletions

View file

@ -266,8 +266,7 @@ defmodule Livebook.Session.Data do
end
def apply_operation(data, {:add_cell_evaluation_stdout, _client_pid, id, string}) do
with {:ok, cell, _} <- Notebook.fetch_cell_and_section(data.notebook, id),
:evaluating <- data.cell_infos[cell.id].evaluation_status do
with {:ok, cell, _} <- Notebook.fetch_cell_and_section(data.notebook, id) do
data
|> with_actions()
|> add_cell_evaluation_stdout(cell, string)

View file

@ -856,6 +856,29 @@ defmodule Livebook.Session.DataTest do
}
}, []} = Data.apply_operation(data, operation)
end
test "adds output even after the cell finished evaluation" do
data =
data_after_operations!([
{:insert_section, self(), 0, "s1"},
{:insert_cell, self(), "s1", 0, :elixir, "c1"},
{:queue_cell_evaluation, self(), "c1"},
{:add_cell_evaluation_response, self(), "c1", {:ok, [1, 2, 3]}}
])
operation = {:add_cell_evaluation_stdout, self(), "c1", "Hello!"}
assert {:ok,
%{
notebook: %{
sections: [
%{
cells: [%{outputs: ["Hello!", _result]}]
}
]
}
}, []} = Data.apply_operation(data, operation)
end
end
describe "apply_operation/2 given :add_cell_evaluation_response" do