From edda01b38c699ca58299ac571133f7094bdbacbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Wed, 3 Jul 2024 15:32:36 +0700 Subject: [PATCH 1/3] Update docs on nested Kino.start_child/1 --- lib/kino.ex | 8 +++++--- lib/kino/js/live.ex | 39 --------------------------------------- 2 files changed, 5 insertions(+), 42 deletions(-) diff --git a/lib/kino.ex b/lib/kino.ex index ac387e40..f2eac1b1 100644 --- a/lib/kino.ex +++ b/lib/kino.ex @@ -428,9 +428,11 @@ defmodule Kino do > or `c:Kino.JS.Live.init/2`. If you do that, starting the process > will block forever. > - > Note that creating many kinos uses `start_child/1` underneath, - > hence the same restriction applies to starting those. See - > `c:Kino.JS.Live.init/2` for more details. + > Creating many kinos uses `start_child/1` underneath, which means + > that you cannot use functions such as `Kino.DataTable.new/1` in + > `c:GenServer.init/1`. If you need to do that, you must either + > create the kinos beforehand and pass in the `GenServer` argument, + > or create them in `c:GenServer.handle_continue/2`. """ @spec start_child( Supervisor.child_spec() diff --git a/lib/kino/js/live.ex b/lib/kino/js/live.ex index 3a92dc17..27a040b6 100644 --- a/lib/kino/js/live.ex +++ b/lib/kino/js/live.ex @@ -201,45 +201,6 @@ defmodule Kino.JS.Live do Invoked when the server is started. See `c:GenServer.init/1` for more details. - - > #### Starting other kinos {: .warning} - > - > It is generally not possible to start kinos inside the `c:init/2` - > callback, as such operation would block forever. In case you need - > to start other kinos during initialization, you must start them - > beforehand and pass as an argument to `c:init/2`. So instead of - > - > defmodule KinoDocs.Custom do - > def new() do - > Kino.JS.Live.new(__MODULE__, {}) - > end - > - > @impl true - > def init({}, ctx) do - > frame = Kino.Frame.new() - > {:ok, assign(ctx, frame: frame)} - > end - > - > ... - > end - > - > do the following - > - > defmodule KinoDocs.Custom do - > def new() do - > frame = Kino.Frame.new() - > Kino.JS.Live.new(__MODULE__, {frame}) - > end - > - > @impl true - > def init({frame}, ctx) do - > {:ok, assign(ctx, frame: frame)} - > end - > - > ... - > end - > - > Also see `Kino.start_child/1`. """ @callback init(arg :: term(), ctx :: Context.t()) :: {:ok, ctx :: Context.t()} | {:ok, ctx :: Context.t(), opts :: keyword()} From 05d4458688a20ced25648abb6445386654d23382 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Wed, 3 Jul 2024 15:48:03 +0700 Subject: [PATCH 2/3] Up --- lib/kino/js/live.ex | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/kino/js/live.ex b/lib/kino/js/live.ex index 27a040b6..d71663ec 100644 --- a/lib/kino/js/live.ex +++ b/lib/kino/js/live.ex @@ -201,6 +201,9 @@ defmodule Kino.JS.Live do Invoked when the server is started. See `c:GenServer.init/1` for more details. + + If you want to create other kinos on initialization, see the + limitations described in `Kino.start_child/1`. """ @callback init(arg :: term(), ctx :: Context.t()) :: {:ok, ctx :: Context.t()} | {:ok, ctx :: Context.t(), opts :: keyword()} From 76deb39a027047868c03bd4d7fe9447ec34aa0ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Wed, 3 Jul 2024 11:28:14 +0200 Subject: [PATCH 3/3] Update lib/kino.ex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: José Valim --- lib/kino.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/kino.ex b/lib/kino.ex index f2eac1b1..bb5066f9 100644 --- a/lib/kino.ex +++ b/lib/kino.ex @@ -428,7 +428,7 @@ defmodule Kino do > or `c:Kino.JS.Live.init/2`. If you do that, starting the process > will block forever. > - > Creating many kinos uses `start_child/1` underneath, which means + > On creation, many kinos use `start_child/1` underneath, which means > that you cannot use functions such as `Kino.DataTable.new/1` in > `c:GenServer.init/1`. If you need to do that, you must either > create the kinos beforehand and pass in the `GenServer` argument,