Skip to content

Commit

Permalink
Update docs on nested Kino.start_child/1 (#452)
Browse files Browse the repository at this point in the history
Co-authored-by: José Valim <[email protected]>
  • Loading branch information
jonatanklosko and josevalim authored Jul 3, 2024
1 parent a30bcff commit bca0dfb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 41 deletions.
8 changes: 5 additions & 3 deletions lib/kino.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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.
> 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,
> or create them in `c:GenServer.handle_continue/2`.
"""
@spec start_child(
Supervisor.child_spec()
Expand Down
40 changes: 2 additions & 38 deletions lib/kino/js/live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -202,44 +202,8 @@ defmodule Kino.JS.Live do
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`.
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()}
Expand Down

0 comments on commit bca0dfb

Please sign in to comment.