livebook-dev / kino

Client-driven interactive widgets for Livebook

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why Kino.listen doesn't return a pid?

jannikbecher opened this issue · comments

kino/lib/kino.ex

Lines 419 to 428 in 78e58cf

defp async(fun) do
{:ok, _pid} =
Kino.start_child(%{
id: Task,
start: {Kino.Terminator, :start_task, [self(), fun]},
restart: :temporary
})
:ok
end

Is there a specific reason why :ok is returned instead of the pid?
It would be nice to be able to do something like this:

job_pid = Kino.listen(5000, fn i -> IO.puts(i) end)

Kino.Control.button("Kill job")
|> Kino.render()
|> Kino.listen(fn _ -> Process.exit(job_pid, :kill) end)

Can you please send a PR?

Just for reference:
Process.exit(job_pid, :kill) kills the whole cell. Instead use Kino.terminate_child(job_pid)